Angular4_格式化金钱或者重量

前端之家收集整理的这篇文章主要介绍了Angular4_格式化金钱或者重量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

| number:'1.2-2'


< td >{{item.weight| number:'1.2-2'}} </ td >

效果

官网文档:

DecimalPipe

npm Package @angular/common
Module import {DecimalPipe} from'@angular/common';
Source common/src/pipes/number_pipe.ts
NgModule CommonModule

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.

whereexpressionis a number:

  • digitInfois astringwhich has a following format:
    {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
  • minIntegerDigitsis the minimum number of integer digits to use. Defaults to1.
  • minFractionDigitsis the minimum number of digits after fraction. Defaults to0.
  • maxFractionDigitsis the maximum number of digits after fraction. Defaults to3.
  • localeis astringdefining the locale to use (uses the currentLOCALE_IDby default)

For more information on the acceptable range for each of these numbers and other details see your native internationalization library.

Example

  1. @Component({
  2. selector: 'number-pipe',
  3. template`<div>
  4. <!--output '2.718'-->
  5. <p>e (no formatting): {{e | number}}</p>
  6. <!--output '002.71828'-->
  7. <p>e (3.1-5): {{e | number:'3.1-5'}}</p>
  8. <!--output '0,002.71828'-->
  9. <p>e (3.5-5): {{e | number:'4.5-5'}}</p>
  10. <!--output '0002,71828'-->
  11. <p>e (french): {{e | number:'4.5-5':'fr'}}</p>
  12. <!--output '3.14'-->
  13. <p>pi (no formatting): {{e | number}}</p>
  14. <!--output '003.14'-->
  15. <p>pi (3.1-5): {{e | number:'3.1-5'}}</p>
  16. <!--output '003.14000'-->
  17. <p>pi (3.5-5): {{e | number:'3.5-5'}}</p>
  18. </div>`
  19. })
  20. exportclass NumberPipeComponent {
  21. pi number = 3.14;
  22. e2.718281828459045;
  23. }
原文链接:https://www.f2er.com/angularjs/145367.html

猜你在找的Angularjs相关文章