To clarify, the problem is how to round a number like this. i.e. 1.512 should round to 1.5 and 2.123 should round to 2 and 2.323 should round to 2.5 (javascript)
Asked
Active
Viewed 1,410 times
3
-
[This answer](http://stackoverflow.com/a/17998232/893780), although meant for Java, works fine. – robertklep Dec 14 '13 at 12:38
3 Answers
8
[1.512, 2.123, 2.323].forEach(function(currentNumber){
console.log(Math.round(currentNumber * 2) / 2);
});
Output
1.5
2
2.5

thefourtheye
- 233,700
- 52
- 457
- 497