[thelist] JS: Rounding floats
Frank
lists at frankmarion.com
Mon Dec 8 13:59:23 CST 2003
I'm trying to "dollar format" some calculated floats. I'm currently using this
// Rounds number to x decimal places, defaults to 2
function round_num(number,x) {
x = (!x ? 2 : x);
return Math.round(number*Math.pow(10,x))/Math.pow(10,x);
}
The downside is that if the calculation turns out to end in a zero, the
zero is omitted. Thus
5.00 = 5
1.50 = 1.5
Does anyone have a very tight and concise manner of either padding for the
dollar-format display?
--
Frank Marion lists at frankmarion.com Keep the signal high.
More information about the thelist
mailing list