3

How to use the Angular Decimal pipe to display the most 5 significant digits from a number as follows:

123.456789 => 123.45
12.3456789 => 12.345
0.12345678 => 0.12345
0.00123456 => 0.00123
1234567.89 => 1234567

Some extreme cases

12         => 012.00

1 Answer 1

3

It should be as follows,

  <h1>{{ amount |  number:'3.2-2'}} </h1>

'3.2-2' means:

  • A minimum of 3 digit will be shown before decimal point

  • It will show at least 2 digits after decimal point

  • But not more than 2 digits

DEMO

3
  • 1
    Thanks for the answer. What I am looking for is to keep only the most significant 5 digits. That format will not work on the second example. Commented Dec 3, 2017 at 8:55
  • In that case write your own pipe Commented Dec 3, 2017 at 8:56
  • 1
    Excellent explanation Commented Dec 19, 2018 at 18:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.