I found this post on rounding via my RSS reader and started giggling since I myself wrestled with this problem a while back. I too started out with string operations etc. but ended up (after some discussion at the office) with a very easy solution.
The below code is in Java but should be easily convertable to JavaScript or any other language that allows you to round a number… The v-variable is a float holding the value we would like to round to .0 or .5:
int value = Math.round(v * 2); float result = (float)value / 2;
It’s so simple it’s scary…
Update 3 May 2006: Updated the code based on feedback in comment.