在 HTML 页面中,我希望十进制数字的输出只有两个位置而不是三个 - 示例:13.16
而不是 13.167
。
但是当我尝试设置它时它不起作用。我如何使用下面的代码来做到这一点?
currentJobStatus.push(
cncActiveState[0].totaltime * 100 /
Number(stdcycletime[0].Standard_Cycle_Time)
).toFixed(1);
我尝试过使用toFixed(1)
函数,但它不起作用。
这是我的node.js代码:
currentJobStatus.push(
cncActiveState[0].totaltime * 100 /
Number(stdcycletime[0].Standard_Cycle_Time)
).toFixed(1);
这是我的 angular.js 代码:
<ngx-gauge
[type]="gaugeType"
value={{item.currentJobStatus}}
[thresholds]="thresholdConfig"
label=""
[append]="gaugeAppendText"
[thick]="8"
size="100">
</ngx-gauge>
输出中的 currentJobStatus
给了我 13.167
,但我只想要 13.16
最佳答案
尝试使用类型转换...toFixed 对字符串不起作用。
console.log(parseFloat(13.167).toFixed(2));
关于javascript - 我想减少下面代码中的小数点长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56161531/