Javascript或Jquery舍入到小数点后1位

LeB*_*eau 4 javascript math jquery rounding

我需要舍入到小数点后1位

如果我的号码是80.02,我需要它是80.1.

试着

Math.ceil( (80.02).toFixed(1) ) but this rounds the number up to 81
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Mil*_*war 6

使用Math.ceil( number * 10 ) / 10;了四舍五入

将它固定到一个小数位

(Math.ceil( number * 10 ) / 10).toFixed(1);

工作小提琴


小智 -1

你应该使用地板而不是天花板

Math.floor( (80.02).toFixed(1) )
Run Code Online (Sandbox Code Playgroud)