Long decimals

New releases and general discussions.

Post » Mon Nov 12, 2007 12:23 pm

I create a new dx9 game, and added a sprite with the variable 'Time'. I need to increment this value by 0.1 by pressing the up arrow. I made a text object, and always set its text to my sprite's private variable 'Time'. The number that it displayed when 0.1 was added was: 0.100000001490116 :? .
B
2
S
1
G
5
Posts: 31
Reputation: 1,462

Post » Mon Nov 12, 2007 1:56 pm

Floating point numbers aren't 100% precise. The solution would be to display your number to only a certain number of decimal places, using the Format Decimal Number system expression:

FormatDecimal(Sprite('Time'), 6)

would give the number to 6 decimal places, which in the above case, is about the range of accuracy.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 5 guests