Problem/bug with array and decimals

Get help using Construct 2

Post » Sat Aug 15, 2015 4:17 pm

I don't know what happen but when I use array C2 say:
0.05 + 0.01 = 0.060000000000000005

Example:
https://dl.dropboxusercontent.com/u/128712958/test.capx


Source code:
Image
Result:
Image

Thank you.
B
10
S
5
G
1
Posts: 28
Reputation: 1,456

Post » Sat Aug 15, 2015 5:01 pm

That's the problem with floating point numbers...

https://www.youtube.com/watch?t=68&v=PZRI1IfStY0
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,870

Post » Sat Aug 15, 2015 5:39 pm

And is there any easy solution?
B
10
S
5
G
1
Posts: 28
Reputation: 1,456

Post » Sat Aug 15, 2015 5:42 pm

Stick with integers and divide by 100 only when you need to get the value as a decimal.
ImageImageImage
B
72
S
22
G
290
Posts: 3,884
Reputation: 159,509

Post » Sat Aug 15, 2015 5:54 pm

most certainly not the best way...but

test.capx
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

Post » Sat Aug 15, 2015 6:08 pm

Like @blackhornet said, work with integers:

Image
B
15
S
6
Posts: 105
Reputation: 1,356

Post » Sat Aug 15, 2015 6:27 pm

Thanks for all your comments.

I decide to use the *100 /100 solution, but adding a round().
With this I can use the array and I don't need to worry every time to add a /100
Image
B
10
S
5
G
1
Posts: 28
Reputation: 1,456


Return to How do I....?

Who is online

Users browsing this forum: dioking, mekonbekon and 3 guests