image_xscale becomes decimal

K

krugen

Guest
I setup an array of value for setting the image_xscale start from 1 to 0.1, decrement of 0.1.

image_xscale = array[index];

so what I expect is that as the loop continue, the image_xscale should follow the array value, but what I get is decimal slightly smaller than the value I set it to, why is that?

Is there a way to stop this from happening?
 
T

ThePropagation

Guest
Why do you need an array? just say if image_xscale > 0.1 image_xscale -= 0.1; else image_xscale = 1;
 
K

krugen

Guest
Why do you need an array? just say if image_xscale > 0.1 image_xscale -= 0.1; else image_xscale = 1;
I tried this before the array and I get decimal numbers.
I then used array but I still get decimal numbers.
It's not that I did not did what you suggested.
I did.
 
T

ThePropagation

Guest
so do you want decimal or not? I don't understand what you want if you're subtracting by decimal values you're going to get a decimal value
 
L

Lonewolff

Guest
I tried this before the array and I get decimal numbers.
You subtract a decimal value from another value and your result is a decimal? I can't possibly imagine why? :p

Maybe you should tell us what your interpretation a decimal number is?
 
K

krugen

Guest
You subtract a decimal value from another value and your result is a decimal? I can't possibly imagine why? :p

Maybe you should tell us what your interpretation a decimal number is?
Sorry, what I mean is:

originally:
image_xscale = 1;

image_xscale -= 0.1; (give me 0.90000133433434)

and becoz of that, if image_xscale == 0.9 does not work

is there a way to prevent getting 0.900000010203020?
 
L

Lonewolff

Guest
That's how 'double precision' works. Which is how computers work.

I'd never recommend comparing against exact values as they will no doubt be stored differently internally. I'd compare with greater or less than.
 

TheouAegis

Member
You start with a value of 1. You subtract 0.1 from that value, you expect 0.9. so traffic is 0.1 again you expect 0.8. the problem is you are not actually working with decimals, you are working with floating points. Most of those values are not compatible with floating points; you can get a damned near close approximation, but rarely that exact number. that is likely what you are seeing in the discrepancies.

If for whatever reason you need more precision, set your values to whole numbers and then divide by 10.
 

I'm lost

Member
Sorry, what I mean is:

originally:
image_xscale = 1;

image_xscale -= 0.1; (give me 0.90000133433434)

and becoz of that, if image_xscale == 0.9 does not work

is there a way to prevent getting 0.900000010203020?

Youre doing HTML export, aren't you?
Beacuse this html export is having this issue for a long time where 1 + 1 is not equal to 2, but to 2,00000001961561

Rounding seems like the only solution
 
K

krugen

Guest
Youre doing HTML export, aren't you?
Beacuse this html export is having this issue for a long time where 1 + 1 is not equal to 2, but to 2,00000001961561

Rounding seems like the only solution
Got it. You're a lifesaver!
 
Top