PDA

View Full Version : Rounding off calculations


mastahkaz
01-30-2003, 12:42 PM
When doing calculations in javascript how do I round something to something other than a whole number? Like the nearest 10ths or 100ths.

right now i'm just using X = Math.round(A + B)

The Quinn
01-30-2003, 02:08 PM
For 10ths:
X = Math.round((A + B) * 10) / 10

For 100ths
X = Math.round((A + B) * 100) / 100

Hope that helps you.

Dr. Web
01-30-2003, 03:38 PM
how about this: