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: 26
Reputation: 1,452

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,650

Post » Sat Aug 15, 2015 5:39 pm

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

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
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sat Aug 15, 2015 5:54 pm

most certainly not the best way...but

test.capx
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

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: 26
Reputation: 1,452


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Microbex, totoe and 18 guests