+ 1
How to use mod(%) with doubles (java)?
I have the doubles d,c2. I want to do the following: c2 = (d2*1000)%1000; But it gives me an error of possibility of loss of data... Please help me! https://code.sololearn.com/c3SW5DMSm39a/?ref=app
4 Respuestas
+ 3
line 113: int c2;
d2 is a double.
I am not sure what your code does so I can not tell which version is better.
a) double c2;
b) c2 = (int)(d2 * 1000) / 1000;
+ 2
Btw: You should be familiar with double precision. I never used modulus operator with doubles. But I think it causes rounding problems.
+ 1
Thanks Denise! Thanks a lot!
+ 1
Giorgos Your welcome :)