Hello, friends! ![:smiley: :smiley:](https://forum.gdevelop.io/images/emoji/apple/smiley.png?v=12)
In this very old post it is explained that the result that the person who created the topic thought was a bug is actually not a bug: Plus/minus action with decimal numbers in variables
Anyway, how to deal with numbers like that when we need the exact value?
My example:
Here I expected 488.1
Thanks!
You can use the ceilTo(<value>, <decimal places>) function in math tools.
Like this: ceilTo(488.099999, 1), which evaluates to 488.1
1 Like
I saw this expression on Wiki but I couldnât understand and I thought it was not useful in my case ![:sweat_smile: :sweat_smile:](https://forum.gdevelop.io/images/emoji/apple/sweat_smile.png?v=12)
Thanks, weadsy1!!! ![:handshake: :handshake:](https://forum.gdevelop.io/images/emoji/apple/handshake.png?v=12)
Glad that worked. Yeah for some reason it is super vague, I only figured it out because the syntax of the arguments are similar to how Excel does it, so it was a bit of a lucky guess on my part lol.
1 Like
May you give me an example, and tell me, do you have to do this for each possible number that it does this with?
Iâm going to use the example I gave when I opened this topic so you can compare the results. With the expression ceilTo would be:
Events
Debugger
![image](https://forum.gdevelop.io/uploads/default/original/3X/a/e/aeab031bace06e08336fe0aa1dd98cbc76940b22.png)
Sorry, I donât know if I understand that question
, but Iâll try to answer, hehe. In my example I have a calculation, but instead of putting the numbers I could put other variables. Something like this:
Scene Variables
Events
Debugger
![image](https://forum.gdevelop.io/uploads/default/original/3X/e/9/e9797781783d94cfb20689d3acefae4ba30a2d8a.png)
With this I can change the variables to change my result if I want. And just to clarify the result is 11.9 because Iâm using ceilTo, but without it will be:
![image](https://forum.gdevelop.io/uploads/default/original/3X/7/8/78a3adb21cf68288a2bb728554731ffbf683ada0.png)
Also, you can go the other way if you prefer if you are using texts to show the results. Using the âExtended Math Supportâ extension, it will give your project additional math functions to use. One of them is âToFixedStringâ which formats a number to use the specified number of decimal places.
Example:
After installed the extension, I used the expression. Notice that Iâm using to change the text of my object Text:
I hope my explanation didnât get confused.