SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    math.round help (got it nearly right!)

    Hello i was just wondering if anyone could help.

    I have this code:

    Code:
                      <!-- ****************** TOTAL PRICE ****************** -->   
    {
    totalprice = document.mf.cpuprice.value*1 + document.mf.mbprice.value*1 + document.mf.ramprice.value*1
     + document.mf.caseprice.value*1 + document.mf.hdprice.value*1 + document.mf.graphicsprice.value*1
     + document.mf.monitorprice.value*1 + document.mf.printerprice.value*1 + document.mf.mouseprice.value*1
     + document.mf.keyboardprice.value*1 + document.mf.storageprice.value*1 + document.mf.cddvdprice.value*1
     + document.mf.cddvd2price.value*1 + document.mf.networkprice.value*1 + document.mf.modemprice.value*1
    + document.mf.scannerprice.value*1 + document.mf.speakersprice.value*1 + document.mf.webcamprice.value*1
    document.mf.totalprice.value = totalprice;
    
    
                      <!-- ****************** TOTAL PRICE + VAT ****************** -->  
    
    vatprice = (document.mf.cpuprice.value*1 + document.mf.mbprice.value*1 + document.mf.ramprice.value*1
     + document.mf.caseprice.value*1 + document.mf.hdprice.value*1 + document.mf.graphicsprice.value*1
     + document.mf.monitorprice.value*1 + document.mf.printerprice.value*1 + document.mf.mouseprice.value*1
     + document.mf.keyboardprice.value*1 + document.mf.storageprice.value*1 + document.mf.cddvdprice.value*1
     + document.mf.cddvd2price.value*1 + document.mf.networkprice.value*1 + document.mf.modemprice.value*1
    + document.mf.scannerprice.value*1 + document.mf.speakersprice.value*1 + document.mf.webcamprice.value*1)*1.175
    document.mf.vatprice.value = vatprice;	
    
    document.mf.vatprice.value = Math.round(document.mf.vatprice.value*100)/100;
    
    <!-- ****************** VAT PRICE ****************** --> 
     
    vat = (document.mf.vatprice.value - document.mf.totalprice.value)
    document.mf.vat.value = vat;	
    
    document.mf.vat.value = Math.round(document.mf.vat.value*100)/100;
    
    <!-- ****************** SHIPPING PRICE ****************** -->  
    
    shipprice = document.mf.shippingprice.value*1
    document.mf.shipprice.value = shipprice;
    
    
    <!-- ****************** FINAL PRICE ****************** -->  
    
    finalprice = document.mf.shippingprice.value*1 + document.mf.vatprice.value*1
    document.mf.finalprice.value = finalprice;
    
    document.mf.finalprice.value = Math.round(document.mf.finalprice.value*100)/100;
    }
    }
    Now i'm trying to get it to display whole number values.

    At the moment in the final price box it still shows (for example) 5814.8 rather than 5814.80

    Basically i just need to add that bloody 0 on the end of it.

    Sometimes it is fine but when i select numbers what do not add up evenly it goes wrong like that.

    Can anyone help?

    thanks.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var x = 21.2
    alert(x.toFixed(2));


Bookmarks

Posting Permissions

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