Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

javascript - 四舍五入至小数点后两位(仅在必要时)(Round to at most 2 decimal places (only if necessary))

I'd like to round at most 2 decimal places, but only if necessary .

(我想最多舍入小数点后两位,但仅在必要时才可以 。)

Input:

(输入:)

10
1.7777777
9.1

Output:

(输出:)

10
1.78
9.1

How can I do this in JavaScript?

(如何在JavaScript中执行此操作?)

  ask by stinkycheeseman translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

使用Math.round(num * 100) / 100


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...