Announcement

Collapse
No announcement yet.

Math Rounding & Abs Value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Math Rounding & Abs Value

    I been trying to use rounding and Abs value for number variables. For some it's been giving me errow message. What am I doing wrong?

    ex)

    var aValue = 20;
    var bValue = 21;

    var myValue = aValue / bValue * 100; //Should be 95.238095238..

    myValue = round(myValue); //should be 95

    Thanks,

    Billy
    Last edited by buzybill; 06-26-2007, 02:57 PM.

  • #2
    Billy
    This line in your code
    myValue = round(myValue);
    should be written as follows
    myValue = Math.round(myValue);
    Alex

    Comment


    • #3
      Thanks !!

      Thanks Alexis!

      Comment


      • #4
        Billy
        You are most welcome
        Alex

        Comment


        • #5
          One more thing!

          What function would I use if I want to have a number specific up to 3 decimal point

          ex)

          x = 15.333333333;
          function -->
          x = 15.333

          Thanks,

          Billy

          Comment


          • #6
            Billy
            You would use the .toFixed() method to define a specific number of decimals eg myVar = x.toFixed(3)
            Alex

            Comment


            • #7
              Not a number?

              I guess after You use myVar = x.toFixed(3) it no longer a number, but string. Is that correct?

              Thanks,

              Billy

              Comment


              • #8
                Billy
                That is correct. The .toFixed() method converts a number to a string. You can however convert it back to a number by multiplying it by 1
                Alex

                Comment

                Working...
                X