Help! Money calculator

Hi! I’m making a money counter, but there seem to be some weird glitches. Adding 1p is fine until the 6th time where it says £0.060000000 and then is fine again until the 10th time where it says 0.0999999999. Is it something to do with the array?

Thanks if you can help.

4 Likes

Gotta love floating point imprecision! When computers store decimals, they kinda estimate the decimal instead of storing it normally. You have to prevent them from being stored as decimals. To do this, just multiply every number in the lookup array by 100 and then divide by 100 before showing the result! This will stop your numbers from being stored in decimal form, which should stop the imprecision!


Thank you! That was an amazing explanation, very detailed! Ill send the finished project, Thanks again!

1 Like

More help needed as I wanted it to say (eg.) £85.50 (with the zero at the end, not just £85.5) but I can’t think how.

1 Like

You could use the “convert (0) to text” block in the Text tab (advanced section)
Then you could check to make sure that the 3rd to last character in the string is a “.”, and if it isn’t then it means that you need to add an extra “0” to the string before displaying it.