首页 > 解决方案 > number pipe number:'1.0-0' 是否对数字进行四舍五入?

问题描述

我使用 number:'1.0-0' 来隐藏任何小数位。它是否使数字四舍五入,因为我听说有人说如果确实如此,那对我来说将是一个问题。

{{file?.progress | number:'1.0-0'}}

标签: angular

解决方案


如 angular docs 中所述,它将 round

如果未指定参数,则函数使用此舍入方法舍入到最接近的值。该行为不同于 JavaScript Math.round() 函数的行为。例如,在以下情况下,管道向下舍入 Math.round() 向上舍入:

-2.5 | number:'1.0-0'
> -3
Math.round(-2.5)
> -2

https://angular.io/api/common/DecimalPipe


推荐阅读