最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use toFixed(2) in ng-bind angularjs - Stack Overflow

programmeradmin2浏览0评论

I am using ng-bind to bind the value of price

 <td><span ng-bind="'$' o.Price"></span></td>

but it is taking value like this 281.96000000000004 so how can I restrict this value in view so it takes only two digits after decimal. like 281.96.

I am using ng-bind to bind the value of price

 <td><span ng-bind="'$' o.Price"></span></td>

but it is taking value like this 281.96000000000004 so how can I restrict this value in view so it takes only two digits after decimal. like 281.96.

Share Improve this question edited Aug 14, 2017 at 8:52 AVJT82 73.4k25 gold badges145 silver badges170 bronze badges asked Aug 14, 2017 at 8:51 Gaurav_0093Gaurav_0093 1,0307 gold badges30 silver badges58 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

use the number filter

 <td><span ng-bind="'$' + (o.Price | number : 2)"></span></td>

You can use the currency filter (if it's a price in dollars):

<td><span>{{ o.Price | currency }}</span></td>

you can use angular filter | number : fractionSize for two decimal places fractionSize use:

  <td><span ng-bind="'$' o.Price| number : 2"></span></td>
发布评论

评论列表(0)

  1. 暂无评论