Ok, so I have a dollar amount that is calculated on the page based on amounts entered into textboxes.
The result tends to end up being something like 27.432
how do I round to 2 decimal places for output?
thanks,
Ryan
Printable View
Ok, so I have a dollar amount that is calculated on the page based on amounts entered into textboxes.
The result tends to end up being something like 27.432
how do I round to 2 decimal places for output?
thanks,
Ryan
http://sitepointforums.com/search.ph...by=&sortorder=
Also take a look in the php manual for substr function.
var sum= your total
// - this will round it to 2 decimal places
sum=Math.round(sum*100)/100;
// - the rest here makes sure your number displays
// - at least 2 decimal places
sum=sum.toString();
var dot=sum.substring(sum.indexOf('.',0)+1,sum.length);
if (sum.indexOf('.',0)==-1){sum=sum+'.00'}
else if (dot.length==1){sum=sum+'0'}
thanks,
did the trick.
-Ryan