Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

math ceiling/floor, round? [RESOLVED]

Status
Not open for further replies.
how do you use these functions in RGSS?

I know RGSS defaultly uses math.floor (always rounds down; aka INT() ), but how do you math.floor and common rounding? (5-9, round up, 0-4, round down)
 
Code:
# Take this number as an example
num1 = 4.2
num2 = 4.55
num3 = 4.92

# Just takes out the decimal part. Same as Truncate, i guess
num1.to_i # ==> 4
num2.to_i # ==> 4
num3.to_i # ==> 4
num1.truncate # ==> 4
num2.truncate # ==> 4
num3.truncate # ==> 4

# Returns the smallest integer equal to or greater than the number
num1.ceil # ==> 5
num2.ceil # ==> 5
num3.ceil # ==> 5

# Returns the largest integer that does not exceed the number
num1.floor # ==> 4
num2.floor # ==> 4
num3.floor # ==> 4

#Returns the integer closest to the number
num1.round # ==> 4
num2.round # ==> 5
num3.round # ==> 5

# Returns the absolute value of the mumber (probably 'self')
num1.abs # ==> 4.2
num2.abs # ==> 4.55
num3.abs # ==> 4.92

That´s pretty much the relevant commands to transform a float into an integer. There´re other ways, implicitly or explicitly in code.
 
Bah that's what i get from using my own module and playing with C# form a long time XD

number.round is what I meant, the module I made was like Maths.round(number,decimals)
C# like ;)
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top