Skip to content

Instantly share code, notes, and snippets.

@johnteske
Created January 5, 2017 18:49
Show Gist options
  • Save johnteske/aab61e8a43ca54dc30ac04888a29cbf1 to your computer and use it in GitHub Desktop.
Save johnteske/aab61e8a43ca54dc30ac04888a29cbf1 to your computer and use it in GitHub Desktop.
Liquid number format with commas
{% 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 %}
<!-- _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