I am using Sugarcube 2 in Twine 1.4.2.
I am running a sequence where the player can buy something with the money they have. As a test, I set the starting money to $50 and the cost of the item as $36.42. I want the screen to display the money, the cost of the item, and the money the player has left after subtracting the cost from the money.
<<set $money = 50.00>>\
<<set $totalprice = 36.42>>\
Total cost: $<<print $totalprice>>
Money you have: $<<print $money>>
Money left to spend: $<<print ($money - $totalprice)>>
However, that returns the following:
Total cost: $36.42
Money you have: $50
Money left to spend: $13.579999999999998
I tried changing the numbers, but I can't figure out why the "money left to spend" displays as such a long number and not $13.58. Even more confusing to me is why it only happens to certain numbers and not others:
$<<print (50.00 - 36.49)>>
$<<print (50.00 - 36.48)>>
$<<print (50.00 - 36.47)>>
$<<print (50.00 - 36.46)>>
$<<print (50.00 - 36.45)>>
$<<print (50.00 - 36.44)>>
$<<print (50.00 - 36.43)>>
$<<print (50.00 - 36.42)>>
$<<print (50.00 - 36.41)>>
$<<print (50.00 - 36.40)>>
$13.509999999999998
$13.520000000000003
$13.530000000000001
$13.54
$13.549999999999997
$13.560000000000002
$13.57
$13.579999999999998
$13.590000000000003
$13.600000000000001
This seems like an elementary problem but I can't seem to find anything online about it. Any help will be appreciated, thank you.