I know this will seem like a really stupid question, but I just don’t get why this isn’t working. This:
System.out.println(5 % .10);
And it’s returning:
0.09999999999999973
I really have NO IDEA. I’m just learning Java, and I’m pretty good with C#, so I tried with C# to. C# seemed to return the same thing also.
As others explained, this is due to inaccuracies caused by floating point precision.
You should use BigDecimal, in this case the remainder method for precise arithmetic involving decimals.