SV: [thelist] JavaScript: trim function? [solved]

Damien COLA damiencola at wanadoo.fr
Fri Nov 14 20:15:09 CST 2003


here's the description of the principle :
you have 24.3456
 you multiply it by 100 ( = 2434.56 )
  you ask for the integer with math.round() ( = 2434 )
   you divid the result by 100 again (make sure you divide by 100.0 that
is a FLOAT not an INTEGER, so the result will be a float) ( = 24.34 )

-----Original Message-----
>   function trimNumber(number, digits) {
>     return Math.round(number * Math.pow(10, digits)) / ((Math.pow(10,
> digits) * 1.0));        
>   }

This is perfect actually, since I need to do this on a few numbers not
just one. (Not that I have a clue how it works..never was a math
guy.)



More information about the thelist mailing list