...

View Full Version : javascript format 2 decimal



esthera
12-27-2005, 08:19 AM
I'm trying to format my total to 2 decimal points but it is not working.

here's my code:

myform.txtordertotal.value = parseFloat(myform.txtitemtotal.value) + parseFloat(myform.txttaxtotal.value) + parseFloat(myform.txtshippingtotal.value);
var x=Math.Math.round(myform.txtordertotal.value*100)/100
x=x.toFixed(2)
myform.txtordertotal.value=x

vwphillips
12-27-2005, 10:27 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
<!--
var t = parseFloat(1.11) + parseFloat(22.20) + parseFloat(334.1);
var t=Math.round(t*100)/100
x=t.toFixed(2)
alert(x)
//-->
</script>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum