Game Development Community

Whole number division

by Drew -Gaiiden- Sikora · in Torque Game Builder · 01/31/2006 (12:41 am) · 3 replies

How do I divide two numbers and assign a whole number result? for example (random numbers - no meaning)
%result = 561 / 35;
I'd like %result to just equal 16 rather than 16.0285 or however accurate T2D floats are

#1
01/31/2006 (1:57 am)
Hi.
You could use the rounding functions, like this:
%result = mFloor(561 / 35);
mFloor() will give you the nearest lower integer, while mCeil() will return the nearest higher integer (in your example, 17).

Bye,
Jacopo
#2
01/31/2006 (2:02 am)
Simply use "mFloor(561 / 35)". You can find all the rest of these functions in "mConsoleFunctions.cc".

EDIT: Someone beat me. :)

- Melv.
#3
01/31/2006 (10:01 am)
Thanks guys!