float a = (float) 3.32 ;
float b = (float) 4.32 ;
System.out.println(b%a);
output on my machine is 1.0000002
Why ?
float a = (float) 3.32 ;
float b = (float) 4.32 ;
System.out.println(b%a);
output on my machine is 1.0000002
Why ?
First how to declare a float value as a variable?
float val=3.23f;
About your result.
It is a typical nature of float
.
How to get correct answer? try this way
BigDecimal a = new BigDecimal("3.32") ;
BigDecimal b = new BigDecimal("4.32") ;
System.out.println(b.divideAndRemainder(a)[1]); // 1st element is remainder
Out put:
1
You may need to read about divideAndRemainder()