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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Location
    MD
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Rounding numbers after calculations

    I am trying to round up numbers after a calculation so only 2 digits to the right of the decimal will remain. I am using javascript for the calculation on my web form. I have some equations that multiply by numbers like ".000038"; Can someone help me with the code that will round the numbers to my specifications?


    Thank you,

    Marvin

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts
    try this..


    function roundOff(value)
    {
    value = "" + value //convert value to string
    var whole = "" + Math.round(value * Math.pow(10, 2));

    var decPoint = whole.length - 2;
    if(decPoint != 0)
    {
    result = whole.substring(0, decPoint);
    result += ".";
    result += whole.substring(decPoint, whole.length);
    }
    else
    {
    result = whole;
    }
    return result;
    }

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Location
    MD
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm... I needed this yesterday! Perhaps I can implement a modified version of this code tonight and use it Monday, if the client requests it.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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