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

标签 javascript html node.js angularjs

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

相关文章:

javascript - 第一次替换后如何停止替换字母?

javascript - 为什么 Lightbox 会扩展我的网页?

node.js - 更换费太低

Javascript Ascii 编码

javascript - 如何在 laravel blade 中动态打印 JavaScript 变量

javascript - array() 函数返回一个对象

javascript - SVG 文本边缘未正确对齐

node.js - 使用 pdf2swf 的 NodeJS 生成和执行

javascript - 尝试导致循环的 window.location 或 window.location.href 重定向

javascript - jQuery 悬停显示 div 切换