# Pure values like 0.1 0.2 0.3 0.4 0.5...during adding +0.1

0 favourites
• 6 posts
• Hi to ALL C2 users and masters

I am adding to a global var 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 = 0.999999999

You can check this issue on this shot video:

I don't want use round() and don't want to use floor(x) round down x e.g. floor(5.9) = 5.

I need a pure values like 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 and 1 when i am adding +0.1 to var.

In this video You can see some:

0.300000000004

0.799999999999

0.899999999999

0.999999999999

Even if i cut this variable i don't get my pure values

PLS help

• That's how float numbers work.

If you need only 1 digit after decimal point you can do round(x*10)/10

• This round(x*10)/10 don't work.

I have same situation with var value when i am adding 0.1 to var

0.300000000004

0.799999999999

0.899999999999

0.999999999999

• For perfect values you could use integers an just divide by 10 as the last step.

var = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1

do

var = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1

then whenever you want to use var use var/10.

As to why the decimal version doesn't work is 0.1 can't be perfectly represented in binary. So when adding multiple values together the approximations add up to be more severe. But yeah, rounding like dop says should work.

• This is what i want to avoid ... changin these +0.1 to +1, and in last step divide 1/10 as int this will complicate my code.

I will just change my events rules from "if var >= 1" to "if var > 0.98 then"

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Dop2000 fixed this THX a lot

" You should round the result, after adding 0.1