help with .toFixed(2)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stylishjm
    New Member
    • Jan 2010
    • 27

    help with .toFixed(2)

    Basically Im using parsefloat to help add a certain amount to a variable passed on from another page, but now instead of it appearing as 45.50, it appears as 45.5.
    Code:
    var pay=50,res;
         
         document.getElementById("3").innerHTML = p[1];
         document.getElementById("77").innerHTML = p[1];
         document.getElementById('77').value = document.getElementById('3').innerHTML;
         document.getElementById('4').value = document.getElementById('77').innerHTML;
         document.getElementById('5').value = document.getElementById('77').innerHTML;
    
         
         document.getElementById("3").innerHTML = p[1].replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' ');
         document.getElementById("77").innerHTML = p[1].replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' ');
         document.getElementById("4").innerHTML = parseFloat(p[1]) + 5;
         res = parseFloat(p[1])*( pay / 100);
         document.getElementById("5").innerHTML = parseFloat(p[1]) + res;
    Basically I need to have "5" and "4" to be displayed to 2 decimal places. Ive tried using toFixed(2) but i cant seem to get it to work.
    Also before anyone mentions, I know the site fails to function as it should on google chrome and some other browsers and Im working on that :)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    worked when I tried toFixed().

    Comment

    • stylishjm
      New Member
      • Jan 2010
      • 27

      #3
      Where would I put to.fixed though?
      Thanks

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Code:
        (parseFloat(p[1]) + res).toFixed(2);

        Comment

        Working...