PDA

View Full Version : Why is my float rounding?


newguy4life
07-17-2012, 04:04 PM
Ok, I've never really had this problem before, and it makes no sense to me, maybe somebody can enlighten me.

In the script editor, when I type in:

float $test = 0.1+(.2);

I get:

// Result: 0.3 //

However, when I type in:

float $test = 0.1+(2/10);

I get:

// Result: 0.1 //

Whaaat????


See the problem is I'm trying to evenly separate particles using (particleId%10+1)/10 to evenly space them across a UV grid, but I'm getting wacky results. I'm guessing it's because apparently x/10 = 0. Any idea why this is happening or what I'm supposed to be typing so that I can get accurate decimal results when dividing?

EDIT: found that it works if I multiply by .1 instead of dividing by 10, but I'd still like to know why this happens

NaughtyNathan
07-17-2012, 04:54 PM
both "2" and "10" are integers, and MEL processes them accordingly: 2/10 = 0

if you want MEL to see a number as a float (and process it accordingly) you need to be explicit: 2.0/10.0 = 0.2

(although actually only one value needs to be a float for this to work)

newguy4life
07-17-2012, 05:12 PM
Ah ok thanks Nathan, that makes sense.

CGTalk Moderation
07-17-2012, 05:12 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.