Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: jeaky on September 03, 2014, 10:35:20 AM
-
Hello, I'm creating a shop system, but Float add or Float operator still get incorrect result, such as 25 X 12.4 = 309.9999, not 310. Any help plz...
-
This is usually a rounding error in the variables and not a bug in the action's math. How do you get the values to begin with?
-
Hi,Lane,I have used Float operator and converted the result to string.
-
Looks like a rounding error somewhere. I can repro, and it gets fractionally worse by increasing the count. Using Float Operator (Count * PriceEach = Total) it does calculate correctly, without rounding issues.
Just use Float Operator and Per Frame, rather than looping through incrementally. You could also force it to round the number up, I think the Math actions have a rounding action.
-
Thanks, Lane. But how to change the result of "Int Add" to ""Count" variable, so I can set this variable to Float 1 in Float Operator.Thank you very much.
-
Use the Convert Int To Float action.
-
Thanks,Lane. The Convert Int to Float action have same problem. 6*12.4=74.39999.
-
Are you looping through with Float Add or using Float Operator once/perframe? I could only get it to cause errors when looping through with the count.
If you're still having trouble here is a rounding action.
http://hutonggames.com/playmakerforum/index.php?topic=2073.msg9110#msg9110
-
Yes, I looping through Float Operator every frame, I have read jeanfabre's code, but I don't know what the code means, it's hard to me.
-
Jean's post has an attachment, just download it and drag it into your project hierarchy, then you'll see float round in the action list.
-
FYI - not offering a solution, just a tip... Turn on Debug ( checkbox under the fsm state area), and you'll be down the values of your variables underneath each reference, it'll make it quicker and easier to see at what point things start going wrong.
-
Thanks, Lane. After use Float Round then 2*12.4=25 not equal to 24.8.
Hi, jess84, I have enabled DebugFlow, and seems havn't any error...
-
Here, I went ahead and made an FSM that does it for you. Download the unitypackage or follow the images.
-
Thanks,Lane.Seems can't solve this problem, after you change the single price to 12.4, and the count set to 6, then result will be 74.39999.
-
That's really weird. I went from 1 - 200 it only messed up on the number 6, but changing the cost made it incorrect on other random count numbers as well.
You could do a custom rounding action for 2 decimals I think, but I can't make one while I'm out of town.
Report as bug with a repro scene.