Preserved Topic: how do you round to 2 decimal places? (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: sj, ca, usa |
posted 09-18-2002 23:38
how do you round to 2 decimal places? |
Paranoid (IV) Mad Scientist From: Somewhere over the rainbow |
posted 09-18-2002 23:49
The poster has demanded we remove all his contributions, less he takes legal action. |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 09-18-2002 23:56
Personally, I'd multiply by 100, round off (Math.round()), and then divide by 100. |
Nervous Wreck (II) Inmate From: sj, ca, usa |
posted 09-19-2002 01:31
if you were to multiply and divide by 100, in the case of a '0' ending up at the end (for example, 12.50), it would show up as 12.5 and not 12.50. i need to maintain a consistency with regards to the monetary figures. |
Nervous Wreck (II) Inmate From: sj, ca, usa |
posted 09-19-2002 01:48
actually, i did a little indexOf workaround magic and solved my problem. thanks for the head start slime! |
Paranoid (IV) Inmate From: Dallas, TX |
posted 09-19-2002 04:11
oh come on hecster... how am I suppose to learn from what you did if you don't post it? |
Paranoid (IV) Inmate From: Dallas, TX |
posted 09-19-2002 04:44
hmm... I didn't know IE had implemented .toFixed but it seems to work. code: function precise(num,X) { //num to X decimal places, defaults to 2 When given 123.4 the above function should give back 123.40 for more current browsers that implement Number.toFixed and 123.4 for older ones. |
Maniac (V) Mad Scientist From: 127 Halcyon Road, Marenia, Atlantis |
posted 09-19-2002 07:23
um... I don't know much about the "Math.round()" function, but shouldn't it do something like " Math.round(-2)" for two decimal places? |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 09-19-2002 07:52
Math.round() just rounds a number; for instance, Math.round(1.3) returns 1, and Math.round(5.7) returns 6. |
Maniac (V) Mad Scientist From: 127 Halcyon Road, Marenia, Atlantis |
posted 09-19-2002 17:00
no prob, dude... you want that ol' version of ICQ98? |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 09-19-2002 17:13
No thanks, I think I had that originally, didn't really like *it* either =) |
Nervous Wreck (II) Inmate From: sj, ca, usa |
posted 09-20-2002 01:36
oh, oops ... hehe. here, have a look. it seems to do the trick for me. added a little more code to Slime's code. code: function roundOff(num, decimalplaces)
|
Paranoid (IV) Inmate From: Dublin, Ireland |
posted 09-20-2002 18:45
Would this do ? : |