I’m adding money to my game and It would make a lot of sense for it to be inplemented in a way where cents are available. e.g you can complete a small task for 1 cent.
The problem I am getting is that often instead of displaying 0.11 it will wither display 0.110000000000000
Is this a known issue and is there a fix?
Unfortunately, decimal explosions are common in many languages (they even happen in Excel, but you never notice them because of built in rounding). Since the field you are displaying the money in is a text field, you can use the following trick to force the value to behave:
The scene has 2 text fields - rawValue and adjValue.
The formula takes the dollarsAndCents value, adds 0.0001 giving a value of 1.01199999999
Multiplying by 100 changes the value to 101.1999999999
The Round function changes this to 101
then the division by 100 reverts the value to 1.01
hope this helps
Why the value are presice?.
As can said Poly-puzzles you need truncate your values.
You can also see here for more expressions, and here for similar post like yours with term, “round variable”.
What do you mean by truncate the values, please ?
Look into the Mathematical functions then look for floor, ceil, round …
One more thing! if i have 1.20 it will apear as 1.2!
how can i change this?
Sorry for the delay in getting back you you @Scythe. I created a function and submitted it to GitHub for possible inclusion in the downloadable Extensions. It will take in a numeric value, round the decimals to 2 places, convert it to a string and format it to 2 decimal places.
Here is the configuration, code and usage of the function:
Function Code (with lots of explaination):
Hope this helps,