When I tried this Code:
double d=1.23;
System.out.println(d%1);
The output was: 0.22999999999999998
My Question is: Why?
The short answer is that double is not accurate. The long answer is to understand that you should learn the way double stored in memory
if you want to do accurate calculations, i would use BigDecimal
object of java
BigDecimal num = new BigDecimal("1.23");
System.out.println(num.remainder(new BigDecimal(1)));