handlebars-helper
handlebars-helper copied to clipboard
Add `number` helper
The number helper should provide a set of tools for turning a number into a string representation of the number. Numbers like 1000
can be converted to formats like: 1,000
, one thousand
, 1k
, or 1,000.00
.
dollars
1000
Handlebars
<!-- Number with no arguments -->
${{#number dollars}}
<!-- Number with format argument: quantity -->
${{#number dollars quantity}}
<!-- Number with format argument: word -->
{{#number dollars word}} dollars
<!-- Number with format argument: short -->
${{#number dollars short}}
<!-- Number with format and decimal arguments -->
${{#number dollars quantity 2}}
Output
<!-- Number with no arguments -->
$1,000
<!-- Number with format argument: quantity -->
$1,000
<!-- Number with format argument: word -->
one thousand dollars
<!-- Number with format argument: short -->
$1k
<!-- Number with format and decimal arguments -->
$1,000.00
If we continue to work with Rally - we'd need something that can insert a decimal point. Rally provides currency as a whole integer, lacking any decimal point to denote cents.
causes: {
name: "Country Music Hall Of Fame",
total_raised: 1227800,
donation_count: 300,
current_fundraising_goal: 1500000,
headline: "Let's rally for Country Music Hall Of Fame",
raised_toward_fundraising_goal: 1227800
}