gpt4 book ai didi

javascript - 我想减少下面代码中的小数点长度

转载 作者:行者123 更新时间:2023-12-01 01:00:06 24 4
gpt4 key购买 nike

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com