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
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy needs help with exponent and other math. stuff

    Hi everyone,

    I need some help with math. stuff because I am not too proficient with it.
    If i have this equation:

    1 - (1+b)n
    (where n is an exponent)
    how does it translate in javascript?

    Also, is there a way to round up to the upper thousand value?
    Like if I have a result that is $12867, if I round it up to the nearest thousand, my result is going to be $13000.
    It sounds a bit tricky to do.

    Any help would be much appreciated, thanks!

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    1 - Math.pow(1+b, n);



    Number.prototype.toNearest = function(num) { // num is an exponent of 10
    return Math.round(this/num)*num;
    }

    12867 .toNearest(1000) == 1300

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    To round up:
    Code:
    Number.prototype.toNearest = function(num) { // num is an exponent of 10
        return Math.ceil(this/num)*num;
    }
    
    12867 .toNearest(1000) == 1300
    dumpfi

  • #4
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ...

    Thanks a lot , guys! Much appreciated~


  •  

    Posting Permissions

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