Calculating remainder of two doubles in java

前端 未结 3 1331
独厮守ぢ
独厮守ぢ 2021-01-19 02:04

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

3条回答
  •  感动是毒
    2021-01-19 02:42

    You need to compare your result which allows for rounding error.

    if (remainder < ERROR || remainder > 0.1 - ERROR)
    

    Also, don't use Double when you mean to use double

提交回复
热议问题