Round Float Values
Mel Scripting January 11th, 2008
Descriptions: In Maya 7, if you want to round a float value shorter to 3 decimals or whatever you like, the following is one of the solutions; convert the float to an interger, multiply with 1000 (if you want 3 decimals), add 0.0005 to round out the value, at the end divided it by 1000 again.
//convert to (integer), add 0.0005 and multiply with 1000
float $floatValue = 0.1234567891;
$floatValue = (int) (($floatValue + 0.0005) *1000);
//devide it back
$floarValue = ($floatValue / 1000);
//to print out the result, which is 0.123
print $floarValue;
December 17th, 2008 at 4:20 am
why add 0.0005?
December 17th, 2008 at 10:18 am
Just to round out the value.