Skip to content

Instantly share code, notes, and snippets.

@kennberg
Last active January 2, 2016 20:49
Show Gist options
  • Save kennberg/8359407 to your computer and use it in GitHub Desktop.
Save kennberg/8359407 to your computer and use it in GitHub Desktop.
Google closure template for formatting numbers.
/**
* Format number (integer).
* @param n
*/
{template .formatNumber}
{let $x: floor($n) /}
{if $x >= 1000 and $x < 1000000000}
{if $x < 1000000}
{floor($x / 1000)},
{else}
{floor($x / 1000000)},
{let $y: floor(($x % 1000000) / 1000) /}
{if $y < 10}00
{elseif $y < 100}0
{/if}{$y},
{/if}
{let $z: $x % 1000 /}
{if $z < 10}00
{elseif $z < 100}0
{/if}{$z}
{else}
{$x}
{/if}
{/template}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment