Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round number to nearest .5 decimal

I'm looking for an output of

4.658227848101266 = 4.5

4.052117263843648 = 4.0

the closest I've gotten is

rating = (Math.round(rating * 4) / 4).toFixed(1) 

but with this the number 4.658227848101266 = 4.8???

like image 836
Jeff Voss Avatar asked Oct 15 '13 20:10

Jeff Voss


People also ask

What is 0.5 rounded off to?

0.5 rounded off to the nearest whole number is 1. Since, the value after decimal is equal to 5, then the number is rounded up to the next whole number. Hence, the whole number of 0.5 will be 1.

How do I round to the nearest 0.5 in Excel?

To always round down (toward zero), use the ROUNDDOWN function. To round a number to a specific multiple (for example, to round to the nearest 0.5), use the MROUND function.

Does 0.5 round up or down in Excel?

Excel has a very elementary take on rounding. It's the same method you learned early in grade school: If you're rounding to a whole number, decimals from 0.1 to 0.4 round down and decimals from 0.5 to 0.9 round up.


1 Answers

(Math.round(rating * 2) / 2).toFixed(1) 
like image 142
Dave Avatar answered Sep 17 '22 13:09

Dave