Why is 5 - 4.99 = 0.0100002289? [SOLVED]
When subtracting two float numbers (cost and moneyPaid) the result is (according to the program) 0.0100002289 (also stored in a float). Why does this happen? You don't need a mathematician to figure out that it's wrong. Using other other values still led to similar results. Relevant Code (very shortened, no user interaction): using System; namespace ChangeCalculator { class Program { static float cost = 4.99F; static Coins input; static float moneyPaid; static float changeAmount; static Coins changeCoins; static void Main() { moneyPaid = 5.00F changeAmount = moneyPaid - cost; //changeAmount = 0.0100002289 changeCoins = calculateChange(changeAmount); displayReturn(changeCoins); } } }