AngularJs在乘以100时得出WRONG结果

时间:2015-07-08 06:40:59

标签: javascript angularjs

rank.js

$scope.ranks = [{id: 1, rank:1, cost:0.01, days: 3},
    {id: 2, rank:2, cost:0.009, days: 3},
    {id: 3, rank:3, cost:0.008, days: 3},
    {id: 4, rank:4, cost:0.007, days: 3},
    {id: 5, rank:5, cost:0.006, days: 3},
    {id: 6, rank:6, cost:0.005, days: 3},
    {id: 7, rank:7, cost:0.004, days: 3},
    {id: 8, rank:8, cost:0.003, days: 3},
    {id: 9, rank:9, cost:0.002, days: 3},
    {id: 10, rank:10, cost:0.001, days: 3}
    ]

rank.html

     <div ng-repeat="rank in ranks">
            <h2>លេខរៀងទី {{rank.rank}} សេវា {{rank.cost * 100}}% = ${{100 * rank.cost}}</h2>            
            <p>Rank Number {{rank.rank}} Fee {{rank.cost * 100}}% = ${{100 * rank.cost}}</p>
            <p>កន្លែងមិនទំនេរ Not Available</p>     
     </div>

在浏览器中:rank.html

为什么排名第2和第4位产生错误的结果?我该如何解决?

感谢。

enter image description here

1 个答案:

答案 0 :(得分:2)

您应首先使用number过滤器

过滤您的数字
  

如果输入为null或未定义,则只返回它。如果   输入是无穷大(Infinity / -Infinity)无穷大符号&#39;∞&#39;是   回。如果输入不是数字,则返回空字符串。

${{data.price * rank.cost | number}}

您也可以传递分数大小。像

 ${{data.price * rank.cost | number : 2}}