Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts

    javascript format 2 decimal

    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

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,519
    Thanks
    3
    Thanked 507 Times in 494 Posts
    Code:
    <!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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •