question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Liquidjs divided_by not compatible with Ruby/Shopify Liquid

See original GitHub issue

https://shopify.github.io/liquid/filters/divided_by/

The result is rounded down to the nearest integer (that is, the floor) if the divisor is an integer.Input

{{ 16 | divided_by: 4 }} => 4
{{ 5 | divided_by: 3 }} => 1

Liquidjs:

{{ 5 | divided_by: 3 }} => 1.6666666666666667

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Nowakercommented, Feb 8, 2022

Okay. There’s no way to fix it on the filter level. We’d have to detect 5.0 on the parsing stage, and use our own wrapping type to differentiate between float and integer. I’m not that good with JavaScript to do it for you.

0reactions
harttlecommented, Apr 21, 2022

Supported another argument to enable integer arithmetic:

{{ 5 | divided_by: 3, true }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Differences with Shopify/liquid - LiquidJS
Though we're trying to be compatible with the Ruby version, there are still some differences: Truthy and Falsy. All values except undefined , ......
Read more >
Can't calculate a percentage because divided_by rounds #831
Hey folks, I'm trying to calculate a percentage using liquid and, to my surprise ... If you divided by an integer, the result...
Read more >
divided_by – Liquid template language
Menu. divided_by. Divides a number by another number. The result is rounded down to the nearest integer (that is, the floor) if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found