Reputation: 4665
I have used the number pipe below to limit numbers to two decimal places.
{{ exampleNumber | number : '1.2-2' }}
I was wondering what the logic behind '1.2-2' was? I have played around with these trying to achieve a pipe which filters to zero decimal places but to no avail.
Upvotes: 224
Views: 214428
Reputation: 183
'0.0-0' will give you round formatted number with ','
100000.2 -> 100,000
very cool
Upvotes: 5
Reputation: 8951
Regarding your first question.The pipe works as follows:
numberValue | number: {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
minFractionDigits: Minimum number of integer digits to show after the decimal point
maxFractionDigits: Maximum number of integer digits to show after the decimal point
2.Regarding your second question, Filter to zero decimal places as follows:
{{ numberValue | number: '1.0-0' }}
For further reading, checkout the following blog
Upvotes: 27
Reputation: 23506
The parameter has this syntax:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
So your example of '1.2-2'
means:
Upvotes: 405
Reputation: 1040
'1.0-0' will give you zero decimal places i.e. no decimals. e.g.$500
Upvotes: 2
Reputation: 222522
From the DOCS
Formats a number as text. Group sizing and separator and other locale-specific configurations are based on the active locale.
SYNTAX:
number_expression | number[:digitInfo[:locale]]
where expression
is a number:
digitInfo
is a string which has a following format:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
Upvotes: 11