Game Development Community

Whole numbers

by c-level · in Torque Game Engine · 10/08/2003 (8:55 pm) · 1 replies

How do I round decimals off in the scripting language? I only want whole numbers for my HUD.


For example, if I get 47.893 from a calculation, I'd like just to have 48 at my disposal.

Thanks

#1
10/08/2003 (9:02 pm)
function round(%n) {

	if(%n < 0)
		%f = -1;
	else
		%f = 1;

	%a = mAbs(%n - mfloor(%n));

	if(%a >= 0.5)
		%b = 1;

	return mfloor(%n+(%b*%f));
}

This will round your numbers