Last active
January 2, 2016 20:49
-
-
Save kennberg/8359407 to your computer and use it in GitHub Desktop.
Google closure template for formatting numbers.
This file contains 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
/** | |
* 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
see http://docs.closure-library.googlecode.com/git/class_goog_i18n_NumberFormat.html