ForEachLoop
main mel draw photography about

ForEachLoop

 


 

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;

2 Responses to “Round Float Values”

  1. chenxiang Says:

    why add 0.0005?

  2. Sin Says:

    Just to round out the value.

Leave a Reply

*