簡體   English   中英

我想在下面的代碼中減少小數點長度

[英]I want to reduce the decimal point length in the below code

在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)); 

第1步,取一些變量var foo;

步驟2.將計算部分分配給變量foo = cncActiveState [0] .totaltime * 100 / Number(stdcycletime [0] .Standard_Cycle_Time;

第3步,然后在push()方法中使用toFixed()方法。 currentJobStatus.push(foo.toFixed());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM