Simple Javascript Help!

Discussion in 'OT Technology' started by mondaynightmike, Jan 12, 2005.

  1. mondaynightmike

    mondaynightmike New Member

    Aug 10, 2004
    Likes Received:
    DEFINITELY No *Unlinked* Cock Pics
    Hello all i've got a some in javascript which add's all these values:

    vatprice = (*1 +*1 +*1
      +*1 +*1 +*1
      +*1 +*1 +*1
      +*1 +*1 +*1
      +*1 +*1 +*1
     +*1 +*1 +*1)
    then displays them using this code:

    Code: = vatprice;
    does anyone know what code i need to add in, in order to add 17.5% to the value but at the same time keeping it rounded up.

    I've tried and i've ended up with numbers like 34.324234234 which is correct but i only want the first 2 after the decimal.

    can anyone help?
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Mar 14, 2000
    Likes Received:
    Vancouver, BC, CANADA
    This is what I used in VB. I'm too lazy to understand it again but it does work:

    Function ProperRound(number As Double, Optional places As Integer = 0) As Double
         ProperRound = Sgn(number) * Int((Abs(number) + ((10 ^ -places) / 2)) * 10 ^ places) / 10 ^ places
    End Function
    Edit: 0 places doesn't quite work all the time but it will work for 2

    Edit2: Fuck - I dunno this is some old code that I didn't finish - but you get the idea - needs to be bug fixed

    Edit3: Alright fixed. I think.

    Edit4: So, you didn't really see these changes and now I realize why I changed it (but that didn't work). If you put in 39.995 and round it to 2 places, it outputs 39.99 instead of 40. It does this because it takes 39.995 adds .005 to it to get 40.000. I then multiply it by 100 to get 4000.0. It then Integers that number, but instead of properly integering it to 4000, it integers it to 3999. I don't know why. I then divide it by 100 to get it back to the proper places.

    In other words, I started fucking around with the code after I realized there was a problem, created a new problem and all of this was because the code that was correct, did not produce the proper results.
    Last edited: Jan 12, 2005

Share This Page