当我去掉小数时,它变得四舍五入。但我只想去掉小数点。我的数据是3.7,而我得到的是4。
sample data 3.7
Exp op 3
代码
<li class="temp">Temperature <span> {{Temperature.Ch1Temp | number:0}} </span></li>
发布于 2020-10-11 16:58:43
为什么不使用Math.floor()
?
<li class="temp">Temperature <span>{{ Math.floor(Temperature.Ch1Temp) }}</span></li>
只要记住这也会对负数产生怎样的影响。
Angular JS
此外,正如注释中所提到的,您需要将Math
库绑定到您的控制器中,如this answer中所述,并摘录如下:
$scope.Math = window.Math;
AngularJS示例HERE。
现代角度
如果您使用的是现代的Angular,则需要在组件的Typescript中显式指定Math
库,如下所示:
export class AppComponent {
number = 3.7;
Math = Math; //explicitly bind the Math library so it's usable in template
}
这里有一个有效的Stackblitz示例HERE
发布于 2020-10-11 17:02:48
您可以在js函数中使用parseInt
将数字转换为整数
https://stackoverflow.com/questions/64306637
复制相似问题