SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2000
    Location
    Madawaska, ME, USA
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was wondering if there was an easy way to round numbers, like rounding 28.5633453 to 28.56, or do I need to get a substring of the number (28.563), see if the last digit is greater than 5, then increment the hundredths place digit? Seems like there should be an easy way to do this...(in JavaScript)

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use Math.round like so:

    function roundMe(num,places){
    num *= Math.pow(10,places);
    num = Math.round(num);
    num /= Math.pow(10,places);
    return num;
    }

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anarchos, that function rules! You just saved my **** thanks!
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •