Bad result on a rest between 2 floats

I have 2 floats variables: lets say “money” and “bet”. At some point, I do money = money - bet; or money -= bet;

bet is from 0.05 to 1 and money starts at 10000. Lets take 0.05 for bet. The first rest, money equals 9999.95. The second rest, is 9999.91. And then alternates resting 0.05 or 0.04.

Why is this happening? Any idea?

The float precision is about 7 digits, thus you should not have problems with 10000 and 0.05 - but with 100000 and 0.05 this error would appear, for sure.

If you must work with such wide range of values, declare the variables as double:

var money: double = 1000000;
var bet: double = 0.05;

Double precision is about 16 digits, thus the player can even break the bank without loosing precision.