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
| SitePoint Sponsor |

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
Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.
http://sitepointforums.com/search.ph...by=&sortorder=
Also take a look in the php manual for substr function.
Last edited by Codename49; Jul 8, 2002 at 16:19.
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
Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.
Bookmarks