javascript float 數值運算時會有誤差產生,可以用 toFixed(2) 將浮點數轉換為僅有小數點兩位的數值字串。

JavaScript toFixed() Method

Number Object Reference JavaScript Number Object

Example

Convert a number into a string, keeping only two decimals:

var num = 5.56789;
var n=num.toFixed(2);
The result of n will be:

5.57

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s