Reputation: 17467
I need to round up to 1 decimal place
If my number is 80.02 I need it to be 80.1.
tried
Math.ceil( (80.02).toFixed(1) ) but this rounds the number up to 81
How can I achieve this?
Upvotes: 6
Views: 9074
Reputation: 459
I think it should work perfectly:
parseFloat(13.2*13.23).toFixed(1)
output:174.6
for your 80.02 - 80.0 and for 80.06-80.1 which is good
Upvotes: 2
Reputation: 82231
use Math.ceil( number * 10 ) / 10;
for rounding off
for fixing it to one decimal place
(Math.ceil( number * 10 ) / 10).toFixed(1);
Upvotes: 9
Reputation: 79
Math.round will round up at >= x.5 and round down at < x.5
.ceil round up to the next number
.floor round down to the next number
Upvotes: -1
Reputation: 760
you should use floor instead of ceil
Math.floor( (80.02).toFixed(1) )
Upvotes: -1