Author Topic: Javascript integerpart  (Read 2978 times)

0 Members and 1 Guest are viewing this topic.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Javascript integerpart
« on: January 21, 2012, 05:42:21 am »
How do you get the integerpart of a variable?
so that 1.9 would also be 1
thanks for help!

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Javascript integerpart
« Reply #1 on: January 21, 2012, 05:53:19 am »
Math.floor(number)
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Javascript integerpart
« Reply #2 on: January 21, 2012, 06:08:38 am »
Thanks, that's working! :)

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Javascript integerpart
« Reply #3 on: January 21, 2012, 06:14:43 am »
I believe that works like BASIC's int() though, not like iPart(), meaning that it rounds everything down. So -1.9 is -2 instead of -1...

If you want to have it round then just write a function like
function ipart(x){
if(x<0)return Math.ceil(x);
return Math.floor(x);
}

and use ipart(value) to get the integer part.
« Last Edit: January 21, 2012, 06:14:53 am by ZippyDee »
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Javascript integerpart
« Reply #4 on: January 21, 2012, 06:16:13 am »
Well, as I just use it with positive numbers that doesn't matter.

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Javascript integerpart
« Reply #5 on: January 21, 2012, 06:23:02 am »
Okay, I just wanted to make sure. If you only use it with positive then Math.floor will do the trick for sure.
There's something about Tuesday...


Pushpins 'n' stuff...