How do I add decimals without many numbers appearing?

0 favourites
  • 4 posts
From the Asset Store
Kids Game
$24.50 USD
50% off
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • Hi fellas.

    I try to add the amount of 0.296 each time the user presses a button, (On tap button --> System --> add 0.296 to Variable) but when I test in debug mode the first sum does well 0.296+0.296= 0.592

    But when you add the next 0.296 the result should be 0.888 but this result comes out 0.8879999999999999

    Could you tell me how I can do so that the following sums do not have so many decimals and have a maximum of 3 decimals, that is, 0.888

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can "round" the decimals of a number with a function.

    Create a function that can accept two parameters, the first parameter "value" will be the value that will be truncated, and the second parameter "precision" will be the amount of decimals the value will have after the calculation. The function should return this value:

    round(value * (10 ^ precision)) / (10 ^ precision)

    Hope this can help you.

  • you can multiply by 1000 round the answer to an integer, and then divide by 1000. This may not always work, there are some difficult decimal questions in computer science in general.

  • Thank you very much for your answers.

    I tried both solutions but none of them worked for me, every time I add 0.296 for the third time the figure increases the number of decimals, leaving as follows 0.8879999999999999 and not as a result of a calculator 0.888

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)