MAbs not working?
by Martin Schultz · in Torque Game Engine Advanced · 09/05/2006 (12:43 am) · 5 replies
This morning I was trying to round a number in TSE (MS3) in script using mAbs(...) and it returned always the same non-rounded number to me. I looked then in the script docs I had on my notebook and that doc says mAbs should work like this:
Thanks,
Martin
%val = mAbs(76.3);I fired up TSE and entered in the console
echo( mAbs(76.3) );and it returned
76.3What the hell did I do wrong? I would have expected a rounded 76 value instead of 76.3. Can someone please try this on their build? Maybe I screwed by build somehow.
Thanks,
Martin
#2
09/05/2006 (12:52 pm)
There's also a useful function called mFloatLength. I use that when I just need an integer.ConsoleFunction( mFloatLength, const char *, 3, 3, "(float v, int numDecimals)" "Return a string containing v formatted with the specified number of decimal places.")
#3
Because for the numbers after the decimal point I would the have to check manually if it is below .5 and then do a mFloor and if it is .5 or higher do a mCeil. I thought there would be a function that does that stuff for me... :-)
09/05/2006 (12:53 pm)
Oh, well, I thought mAbs would round a number. Seems like I'm wrong. But isn't there something that automatically rounds a number to the nearest integer value without doing manually a mFloor or mCeil? Because for the numbers after the decimal point I would the have to check manually if it is below .5 and then do a mFloor and if it is .5 or higher do a mCeil. I thought there would be a function that does that stuff for me... :-)
#4
And thanks Brian for your help.
09/05/2006 (1:03 pm)
Ah, thanks Stefan. That answers my question :-)And thanks Brian for your help.
#5
%rounded = mFloor ( %value +0.5)
No conditional logic needed and possibly more efficient than mFloatLength.
09/05/2006 (6:04 pm)
How about:%rounded = mFloor ( %value +0.5)
No conditional logic needed and possibly more efficient than mFloatLength.
Torque Owner Brian Ramage
Black Jacket Games