更新时间:2023-02-21 16:22:28
You're looking for toFixed
:
var x = 4.3455;
alert(x.toFixed(2)); // alerts 4.35 -- not what you wanted!
...but it looks like you want to truncate rather than rounding, so:
var x = 4.3455;
x = Math.floor(x * 100) / 100;
alert(x.toFixed(2)); // alerts 4.34