# decimals & counting change

From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
• Hi everyone...

I was wondering if someone could point me to a thread with a tutorial or example of a decimal system formula that will add variables together and place the decimals in the right place for counting dollars?

say I add four vales of 25,

instead of displaying 100 it will display 1.00 and so on....

Thanks

• ## Try Construct 3

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

Construct 3 users don't see these ads
• In the following, assume the variable valueToAdd is a string value representation of the number you want to add and total is a float value. Using a string, you can check for an existing decimal with the find() method. Given this information, you would use the following to set the total amount after the addtion.

What this does is, first checks if a decimal is present in the valueToAdd (find(valueToAdd, ".") = -1). If the result of the find is -1, no decimal is found so we divide by 100 (float(valueToAdd) / 100). If the result of the find is > -1 the string already contains a decimal so, no need to divide.

https://www.scirra.com/tutorials/77/nat ... uct-2#h2a0

I hope this gets you what you need and good luck with your project.

• In the following, assume the variable valueToAdd is a string value representation of the number you want to add and total is a float value. Using a string, you can check for an existing decimal with the find() method. Given this information, you would use the following to set the total amount after the addtion.

What this does is, first checks if a decimal is present in the valueToAdd (find(valueToAdd, ".") = -1). If the result of the find is -1, no decimal is found so we divide by 100 (float(valueToAdd) / 100). If the result of the find is > -1 the string already contains a decimal so, no need to divide.