我正在使用下面的代码尝试在角中舍入,但是在整个工作过程中,小于0.5的数字被舍入为0。我想把的每一个数字集合到下一个整数。例如0.02应四舍五入为1
{{((data.Virtual.SumCores/data.Physical.SumCores) | number:0)*1}}
发布于 2015-09-18 10:12:19
使用这个
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 }}参考文献
JS Math
发布于 2015-09-18 10:15:35
您可以为此创建一个过滤器:
.filter('roundup', function() {
return function(input) {
return Math.ceil(input);
};
});像这样使用它:
{{ data.Virtual.SumCores/data.Physical.SumCores | roundup }}发布于 2017-02-16 16:01:48
因为所有答案都是基于Math.ceil()函数的,所以您可以简单地添加
$scope.Math=window.Math;放到你的控制器里然后像这样使用它:
{{ Math.ceil(data.Virtual.SumCores/data.Physical.SumCores) }}这样,您就可以访问所有数学函数。
https://stackoverflow.com/questions/32649376
复制相似问题