I have the following code :
Double x = 17.0; Double y = 0.1; double remainder = x.doubleValue() % y.doubleValue();
When I run this I get r
Because of how floating-point numbers are represented.
If you want exact values, use BigDecimal:
BigDecimal
BigDecimal remainder = BigDecimal.valueOf(x).remainder(BigDecimal.valueOf(y));
Another way to to that is to multiple each value by 10 (or 100, 1000), cast to int, and then use %.
int
%