Skip to content
Advertisement

Round a number to nearest .25 in JavaScript

I want to convert all numbers to the nearest .25

So…

5 becomes 5.00
2.25 becomes 2.25
4 becomes 4.00
3.5 becomes 3.50

Advertisement

Answer

Here’s an implementation of what rslite said:

var number = 5.12345;
number = (Math.round(number * 4) / 4).toFixed(2);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement