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.

where expression is a number:

  • 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


 
 
  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.  
  9. <!--output '0,002.71828'-->
  10. <p>e (3.5-5): {{e | number:'4.5-5'}}</p>
  11. <!--output '0 002,71828'-->
  12. <p>e (french): {{e | number:'4.5-5':'fr'}}</p>
  13.  
  14. <!--output '3.14'-->
  15. <p>pi (no formatting): {{e | number}}</p>
  16. <!--output '003.14'-->
  17. <p>pi (3.1-5): {{e | number:'3.1-5'}}</p>
  18.  
  19. <!--output '003.14000'-->
  20. <p>pi (3.5-5): {{e | number:'3.5-5'}}</p>
  21. </div>`
  22. })
  23. export class NumberPipeComponent {
  24. pi: number = 3.14;
  25. e: number = 2.718281828459045;
  26. }

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值