【问题标题】:Angular binding breaking the decimal places角绑定打破小数位
【发布时间】:2013-11-28 21:32:53
【问题描述】:

在我的 $scope 中,我有 tobing=2.00 或 tobind=2.20,我将它绑定到

  <span >{{datasource.tobind}}</span>

我希望我的绑定显示文本始终为“2.00”或“2.20”,最后两位数字,但角度似乎是自动舍入它。它是一种将其设置为文本并将其绑定为字符串的解决方法,但会导致很多地方有逻辑将其转换为数字,然后转换为字符串,这让兔子哭了。请建议如何修复自动舍入。

【问题讨论】:

  • 尝试这样使用&lt;span&gt;{{datasource.tobind| number:2}}&lt;/span&gt;
  • JavaScript 中的井号不存储尾随零。 var x = 2.002

标签: javascript angularjs binding decimal


【解决方案1】:

查看number filtercurrency filter

<span >{{datasource.tobind | number:2}}</span>

或:

<span >{{datasource.tobind | currency}}</span>

【讨论】:

    猜你喜欢
    • 2011-05-31
    • 2011-04-05
    • 1970-01-01
    • 2014-11-24
    • 1970-01-01
    • 2014-07-09
    • 2019-04-18
    • 2016-09-07
    • 1970-01-01
    相关资源
    最近更新 更多