angular - number pipe number:'1.0-0' 是否对数字进行四舍五入?
问题描述
我使用 number:'1.0-0' 来隐藏任何小数位。它是否使数字四舍五入,因为我听说有人说如果确实如此,那对我来说将是一个问题。
{{file?.progress | number:'1.0-0'}}
解决方案
如 angular docs 中所述,它将 round:
如果未指定参数,则函数使用此舍入方法舍入到最接近的值。该行为不同于 JavaScript Math.round() 函数的行为。例如,在以下情况下,管道向下舍入 Math.round() 向上舍入:
-2.5 | number:'1.0-0'
> -3
Math.round(-2.5)
> -2
推荐阅读
- php - 如何在 OpenCart 中运行 CodeIgniter?
- electron - 在我的自定义传输中未调用日志函数
- android - 如何在android另一个活动的操作栏上显示后退按钮
- nginx - Nginx - 添加 server_name 后,所有 url 都显示 404
- reactjs - 使用 mqtt 的 HighCharts 实时数据
- html - html 中的常量,如 C/C++ 中的 #define
- ios - 当应用程序进入前台时显示视图控制器但不知道在 swift 4 中关闭此视图控制器
- javascript - 如何从两个库中导入两个同名的组件?
- asp.net-core - 如何从 .net 核心中的部分视图访问控制器?
- java - 反序列化为没有@type 字段的子类