Rounding to the nearest fraction (i.e. specific decimal place)

Categories: Java, Flex/Flash, HTML/ColdFusion, JavaScript, SQL

I'm working on some "star rating" code and I really wanted to round numbers of to the nearest fraction. While the math is really basic, my math skills are rusty and this took me longer to solve than I care to admit. So I thought I'd just blog the solution for anyone else that might find it useful:

round( value/fraction ) * fraction

Like I said, it's very basic math but is very handy when you want to round to something other than to the closest integer.

Add Comment

Leave this field empty


If you subscribe, any new posts to this thread will be sent to your email address.