Reputation: 483
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)
Upvotes: 3
Views: 1572
Reputation: 239693
[1.512, 2.123, 2.323].forEach(function(currentNumber){
console.log(Math.round(currentNumber * 2) / 2);
});
Output
1.5
2
2.5
Upvotes: 8