-
-
Save virtadpt/95c60f762cff0c95fed20c92a535adb5 to your computer and use it in GitHub Desktop.
Liquid number format with commas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% include numberWithCommas.html number=1 %} | |
{% include numberWithCommas.html number=12 %} | |
{% include numberWithCommas.html number=123 %} | |
{% include numberWithCommas.html number=1234 %} | |
{% include numberWithCommas.html number=12345 %} | |
{% include numberWithCommas.html number=123456 %} | |
{% include numberWithCommas.html number=1234567 %} | |
{% include numberWithCommas.html number=12345678 %} | |
{% include numberWithCommas.html number=123456789 %} | |
{% include numberWithCommas.html number=1234567890 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- _include --> | |
{% assign digits = include.number | split:'' %}{% for digit in digits %}{% assign threeFromEnd = digits.size | minus:forloop.index | modulo: 3 %}{% if threeFromEnd == 2 and forloop.index != 1 %}{{ digit | prepend: ',' }}{% else %}{{ digit }}{% endif %}{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment