I'm mainly waiting for C# to move over a game maker project to Godot, but I have one question. Doesn't GDScript have div? I know / and % is generally the same thing but they do sometimes give different results.

so... whatsup?

What's div? Is it a division operator? If so, the only division operator I've used along all my life was just / :wink:

Can you show us an example of the different results you mentioned?

tileSize = 32; tilew = tileSize tileh = tileSize tileX = x div tilew tileY = y div _tielh

/ works but doesn't snap the object in place like div does, also it's very common in C#, C++, etc.

Looking at the documentation for div (for C/C++) it looks like it divides and returns both the quotient and the remainder in a struct.

Probably the reason you're getting different values is that your using the quotient when you're calling div, while / returns the quotient plus the remainder. You can get the quotient with GDScript using floor(x / y) and the remainder with (x/ y) - floor(x / y), or you might be able to use (x % y) to get the remainder if GDScript supports it.

Alright, now I got, thanks @TwistedTwigleg .

Another way to get the quotient is casting the numbers to int: var a = 7.0 var b = 5 var quotient = int(a) / int(b) # 1 The modulo operator % just works with integers, so to use it or you need to cast both number to integer or use fmod() function.

5 years later