it won't parse float! help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ballygowanboy
    New Member
    • Jul 2007
    • 47

    it won't parse float! help please

    ok, i'm trying to get a return value of a float...... but it keeps giving me a load of numbers!

    how do i make this interger behave?

    the problem is line 39. thanks.

    Code:
    <script language="javascript1.2">
    
    
    function checkreset()
    {
       
       if (confirm('Are you sure you wish to clear the form?'))
       {
          return true
       }
       return false
    }
    
    
    function addnumbers()
    {
    
    // This function reads the values from the input boxes
    // parseFloat converts the input boxes into an integer
    
    var x,y,result;
    a = parseFloat(document.form1.abox.value);
    b = parseFloat(document.form1.bbox.value);
    c = parseFloat(document.form1.cbox.value);
    d = parseFloat(document.form1.dbox.value);
    e = parseFloat(document.form1.ebox.value);
    f = parseFloat(document.form1.fbox.value);
    g = parseFloat(document.form1.gbox.value);
    h = parseFloat(document.form1.hbox.value);
    i = parseFloat(document.form1.ibox.value);
    j = parseFloat(document.form1.jbox.value);
    
    // Then we do the math
    
    result = a + b + c + d + e + f + g + h + i + j;
    
    // And write the result straight to the screen
    document.form1.qbox.value = result;
    document.form1.totalbox.value = result*10.21;
    
    
    // As the function has already done the output, we don’t need a return value
    }
    </script>
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    nope ... parseFloat() handles the values as float :) ... you may use parseInt() instead ... and multiplying a float produces float again ... so you may use the math-methods to round the value

    kind regards

    Comment

    • ballygowanboy
      New Member
      • Jul 2007
      • 47

      #3
      ok, i tried math.round, and that just rounds up the number, which is no good.

      so for example, instead of getting a result of €30.63000000000 0002, i'd like to just get a result of €30.63

      how do i do this?

      thanks

      Comment

      • ballygowanboy
        New Member
        • Jul 2007
        • 47

        #4
        how do i loose the extra zeros?

        i'm multiplying a number by 10.21 in javascript,

        Code:
        document.form1.totalbox.value = "€" + result*10.21;
        how do i remove the extra zeros?

        for example, instead of getting a result of €30.63000000000 0002, i'd like to just get a result of €30.63

        thanks

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          use the toFixed(); method instead ...

          kind regards

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            threads merged ... please don't double post questions ...

            kind regards

            Comment

            • ballygowanboy
              New Member
              • Jul 2007
              • 47

              #7
              Originally posted by gits
              threads merged ... please don't double post questions ...

              kind regards
              no worries, that worked, thanks.

              Code:
              document.form1.totalbox.value = "€" + (result*10.21).toFixed(2);

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                :) glad to hear that ... post back to the forum anytime you have more questions

                kind regards

                Comment

                Working...