Float problem

Hello!

I have made a function which takes a Speed Base Value (float) and a Modifier Value (float), multiply both, then divides the result per 100 and finally, I add the result to the Speed Base Value so I get a base number + a percentage.
I add the screenshot.

The thing is that the total result I get returns a float with a high number of decimals while I only want to get 2 decimals maximum. I add a second screenshot of what I get making a 2% of a Speed Base Value of 180 which returns a total of 183.600006

So I have tried tons of ways to make that number have just two decimals, I dont need more than two.
I add a third screenshot of some of the ways I tried with no success.

I could get just two decimals when showing on the HUD, applying the node ToText(float) directly to the TextBox but thats not what I really want. I just want to get those 2 decimals on the float value itself.

What is really happening?
Why I can not get just two decimals?
Any ideas?

Thank you all

Like this…you have to expand the “to text” node, it gives all these extra options. Set “max fractional digits” to 2 for 2 decimals. Then convert text to string, and string back to the nice clean rounded float. (Text to float directly isn’t compatible)

1 Like

Hi! Thanks for your answer.
I already checked that node and… keeps giving me the same result of 183.600006
I can not understand why always returns all that amount of decimals!!
Have no sense.

Try not to make new answers, add comments below my answer it keeps things neat and easy to read for others.

Notice my input value? 1.55555? I printed that off and it showed 1.56… this node as shown definitely works. You must be changing your float value somewhere else after you round and before you display it to the screen. Show me screen shots of how you actually put this into your HUD, what you have above is just a function with a return node. Modifying the float after that could be causing your issue

Have been controlling the error using Print Strings nodes and I noticed something weird. The problem is when you convert String variable to Float variable.

So…

If I use Print String directly with the String Variable like this:

I get the proper right number, 183.60

But when I use Print String with the Float Variable like this:

I get the wrong weird number, 183.600006

267728-screenshot1.jpg

Okey, after assimilating its just the nature of the Float Variables, I just decided to IGNORE those 0.000006 as a part of how it really works. If I want to show a float value in a TextBox or HUD and get simmilar numbers, I will use ToText (float) node and limit decimals as you said or using any other ways I already listed before.

Thank you.

Links about Float Variables:

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html?fbclid=IwAR3VYpB_QizBBwe_HwsnJvDo_hxpwFLCj1ZwKFx-sGajY09WNPYAB2B_7tY

why not use integer?

This is basically it. A float cannot represent some numbers. If you need to preserve it as a number rather than text for whatever reason you can also store the number and the decimal separately with two integers. Of course, if you merge them back into float you will have the same problem.