I'm trying to format a float number (lets say 341.75) by setting the decimal point to "1". I tried:
var num = 341.75;
alert(num.toFixed(1)); // output: 341.8
alert(num.toPrecision(1)); // output: 341.8
but what I need is 341.7 ! apparently both methods try to round it, is there a way to do that without rounding ?
What about little cheating?
Math.floor(num * 10) / 10
You could subtract 0.05 before formatting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With