Preserved Topic: rounding numbers in JavaScript calculations (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: my mother |
posted 08-17-2000 05:03
I am learning JavaScript and for practice, I wrote my own little script for my website when it is done. There is a problem though. Go to http://members.tripod.com/~Babamba/javascript.htm and type in these numbers: 48, 12, 22 . Is there any way that I can make the huge number round to the nearest hundredth?(spelling?) thanks a lot for your time. |
Maniac (V) Lord Mad Scientist Sovereign of all the lands Ozone and just beyond that little green line over there... From: Stockholm, Sweden |
posted 08-17-2000 08:49 |
Maniac (V) Lord Mad Scientist Sovereign of all the lands Ozone and just beyond that little green line over there... From: Stockholm, Sweden |
posted 08-17-2000 09:00
OK, I got my CAPitalIZAtion off, it's actually Math.round(...). This is one of those picky tags, that needs to be capitalized just this way. I also had some problems with netscape, turns out "long" is a reserved word, heh. I ended up with this code... |
Paranoid (IV) Inmate From: my mother |
posted 08-17-2000 16:25
Thank you for the help. It works great. |
Bipolar (III) Inmate From: Dublin, Ireland |
posted 08-17-2000 16:26
Also, Math.round rounds the number up. Math.floor rounds the number down. |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 08-17-2000 18:26
No, Math.round correctly rounds the numbers, I believe. If you want to round up, use Math.ceil() (short for ceiling, i believe). And Math.floor() does, as you said, round down. |
Paranoid (IV) Inmate From: my mother |
posted 08-17-2000 19:22
Correct. 231 cubic inches = 1 gallon. thanks for the help. I've also posted a brief bio here http://www.ozones.com/forum/Forum1/HTML/000258.html |
Maniac (V) Lord Mad Scientist Sovereign of all the lands Ozone and just beyond that little green line over there... From: Stockholm, Sweden |
posted 08-17-2000 23:44
Yah, I use the Math.floor() function when I'm dealing with random numbers, it helps me be sure not to round the wrong way and get a number one too big. I could get the same effect with the "round up" function, but I always have a hard time spelling that word for the underside of the roof, heh. |