Limit to 2 decimal places with a simple pipe

后端 未结 4 539
难免孤独
难免孤独 2020-12-13 23:10

I have found an example which limits a number to 2 decimal places AND turns the figure into a currency amount- eg £2.55.

{{ number | currency : \'GBP\' : tru         


        
相关标签:
4条回答
  • 2020-12-13 23:22

    Well now will be different after angular 5:

    {{ number | currency :'GBP':'symbol':'1.2-2' }}
    
    0 讨论(0)
  • 2020-12-13 23:26

    Currency pipe uses the number one internally for number formatting. So you can use it like this:

    {{ number | number : '1.2-2'}}
    
    0 讨论(0)
  • 2020-12-13 23:32

    It's Works

    .ts -> pi = 3.1415
    
    .html -> {{ pi | number : '1.0-2' }}
    
    Ouput -> 3.14
    
    1. if it has a decimal it only shows one
    2. if it has two decimals it shows both

    https://stackblitz.com/edit/angular-e8g2pt?file=src/app/app.component.html

    this works for me!!! thanks!!

    0 讨论(0)
  • 2020-12-13 23:36

    Simple solution

    {{ orderTotal | number : '1.2-2'}}
    
    //output like this
    
    // public orderTotal = 220.45892221
    
    //   {{ orderTotal | number : '1.2-2'}} 
    
    // final Output
    //  220.45
    
    0 讨论(0)
提交回复
热议问题