I would like to round numbers to the nearest 0.25-value like this:
2.1 -> 2
2.2 -> 2.25
3.4 -> 3.5
5.6 -> 5.5
9.8 -> 9.75
9.9 -> 10
Is this possible in javascript? Thank you in advance!
I would like to round numbers to the nearest 0.25-value like this:
2.1 -> 2
2.2 -> 2.25
3.4 -> 3.5
5.6 -> 5.5
9.8 -> 9.75
9.9 -> 10
Is this possible in javascript? Thank you in advance!
Just multiply the number by 4
, round it, and divide by 4:
[2.1, 2.2, 3.4, 5.6, 9.8, 9.8, 9.9].forEach(
num => console.log(Math.round(num * 4) / 4)
);