| number:'1.2-2'
<
td
>{{item.weight| number:'1.2-2'}}
</
td
>
效果:
官网文档:
DecimalPipe
PIPE
npm Package | @angular/common |
Module |
|
Source | common/src/pipes/number_pipe.ts |
NgModule | |
Formats a number according to locale rules.
How To Use
number_expression | number[:digitInfo[:locale]]
Formats a number as text. Group sizing and separator and other locale-specific configurations are based on the active locale.
where expression
digitInfo
- is a
string
- which has a following format:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
minIntegerDigits
- is the minimum number of integer digits to use. Defaults to
1
- .
minFractionDigits
- is the minimum number of digits after fraction. Defaults to
0
- .
maxFractionDigits
- is the maximum number of digits after fraction. Defaults to
3
- .
locale
- is a
string
- defining the locale to use (uses the current
LOCALE_ID
by default)
For more information on the acceptable range for each of these numbers and other details see your native internationalization library.
Example
content_copy
1. @Component({
2. selector: 'number-pipe',
3. template: `<div>
4. <!--output '2.718'-->
5. <p>e (no formatting): {{e | number}}</p>
6.
7. <!--output '002.71828'-->
8. <p>e (3.1-5): {{e | number:'3.1-5'}}</p>
9.
10. <!--output '0,002.71828'-->
11. <p>e (3.5-5): {{e | number:'4.5-5'}}</p>
12.
13. <!--output '0 002,71828'-->
14. <p>e (french): {{e | number:'4.5-5':'fr'}}</p>
15.
16. <!--output '3.14'-->
17. <p>pi (no formatting): {{e | number}}</p>
18.
19. <!--output '003.14'-->
20. <p>pi (3.1-5): {{e | number:'3.1-5'}}</p>
21.
22. <!--output '003.14000'-->
23. <p>pi (3.5-5): {{e | number:'3.5-5'}}</p>
24. </div>`
25. })
26. export class NumberPipeComponent {
27. pi: number = 3.14;
28. e: number = 2.718281828459045;
29. }