2016-08-17 65 views
-3

我想四捨五入到小數點後兩位。價格中的十進制小數

輸入: 2.456 2.890

輸出: 2.500 2.900

我怎樣才能做到這一點在JavaScript?

+3

我認爲這可以幫助你,爲什麼你不先谷歌它? http://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places –

+4

可能重複的[如何在javascript中舍入浮點數?](http://stackoverflow.com/問題/ 9453421/how-to-round-float-numbers-in-javascript) –

回答

1

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

+0

我相信你想要Math.ceil()而不是 – csander

+0

im shory我介意2456浮點數2.500 –