Making a calculator - floating point errors?
My first topic here, so please be gentle! :)
I'm starting out in Blueprint, just trying to get to grips with things and figured a calculator might be a nice introductory project to make to get me used to variables/some basic math etc.
I'm simply focusing on addition, but have found that even calculations of low value often lead to unexpected results. I suspect floating point errors, but can find no suitable answer on how to resolve it. Integers are no good, as I need people to use decimal values.
Do you have any suggestions on how to resolve this?
I've attached an image of what I have so far.
If I've approached the whole thing in entirely the wrong way, please say so, but my main interest is knowing how to avoid such errors in future. I come from using GameMaker Studio (don't laugh!), and using real numbers as opposed to integers was very straight forward and you only hit floating point trouble when dealing with HUGE values, something I'm not intending to do here.
Many thanks for helping a newbie
asked Jun 25 '16 at 04:45 PM in Blueprint Scripting
chulk, unfortunately there isn't a built-in blueprint function that will let you convert a float to a string with a specific precision, but at least now you know better how to search for an alternative. I'd recommend doing some searching for plugins or blueprint nodes from the community that solve this rather than trying to build your own solution from lower-level blueprint notes. A search phrase like "float to string with precision" should get you started.
Here's a C++ utility function from the community Wiki that might help (you'd still have to figure out how to turn it into a blueprint node, though): https://wiki.unrealengine.com/Float_as_String_With_Precision
That same author has also created a library of blueprint nodes that install as a plug-in (although I've never used these and it looks like it includes tons of other functionality that you may not need and may make it tricky to install): https://forums.unrealengine.com/showthread.php?3851-(39)-Rama-s-Extra-Blueprint-Nodes-for-You-as-a-Plugin-No-C-Required!/page27&highlight=rama%20keybind
Finally, if you'd rather build your own solution from lower-level nodes, you might want to check out this AnswerHub answer: https://answers.unrealengine.com/questions/94901/how-can-i-set-float-precision.html
If my post helps you, consider marking it as a correct answer. Thanks!
Follow this question
Once you sign in you will be able to subscribe for any updates here