综述-AngularJS [英] RoundUp - AngularJS
本文介绍了综述-AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码尝试在Angular中对进行取整,这在整体上是可行的,但是小于0.5的数字将取整为0.我想取整强>每个数字到下一个整数.例如0.02应该四舍五入到1
I am using the following code to try and roundup in Angular, which on the whole works, however numbers less than 0.5 are rounded to 0. I would like to round up every number to the next whole number. E.g 0.02 should be rounded to 1
{{(((data.Virtual.SumCores/data.Physical.SumCores)| number:0)* 1}}
推荐答案
使用此
Math.ceil(4.4); //Returns 5
Math.ceil(0.002); //Returns 1
过滤器
.filter('roundup', function () {
return function (value) {
return Math.ceil(value);
};
})
HTML
{{ yourdata | roundup }}
参考
这篇关于综述-AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文