Skip to content
Advertisement

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???

Advertisement

Answer

(Math.round(rating * 2) / 2).toFixed(1)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement