我有一个集合,其值类似于 { "pctFail": "0.3515500159795462"}
,当我将其传递给模板并显示为 {{myTemplate}}% 时,它在我的 html 中显示为0.3515500159795462%。如何将其显示为 0.35%?
最佳答案
您可以使用模板辅助方法覆盖数据上下文的属性:
Template.myTemplate.helpers({
pctFail: function () { return this.pctFail.toFixed(2); }
})
然后像以前一样使用{{pctFail}}%
。如果您坚持将数字属性存储为字符串,则需要返回类似 parseFloat(this.pctFail).toFixed(2)
的内容。
关于mongodb - meteor, mongodb, 空格键,如何只显示小数点后两位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27577891/