Introducing Dragonfly Cloud! Learn More

Question: What is the round function in GameMaker?

Answer

The round function in GameMaker is used to round a floating-point number to the nearest whole number. The way it works is by checking the decimal part of the number; if it's 0.5 or higher, the function rounds up, and if it's lower than 0.5, it rounds down.

Here's an example of how you can use the round function:

var myNumber = 2.7; var roundedNumber = round(myNumber); // This will be 3

In this case, roundedNumber would contain the value 3 because 2.7 is closer to 3 than to 2.

It's important to note that round differs from floor and ceil functions:

  • floor always rounds down to the nearest whole number,
  • ceil always rounds up to the nearest whole number.

For instance:

var myNumberDown = 2.7; var flooredNumber = floor(myNumberDown); // This will be 2 var myNumberUp = 2.3; var ceiledNumber = ceil(myNumberUp); // This will be 3

Understanding these differences is crucial when performing various mathematical operations in GameMaker, especially when dealing with graphics or logic that depends on integer values.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.