+ 1
Question about double
public class Program { public static void main(String[] args) { double a = 12.3; double b = 12.0; double c = a-b; System.out.println(c); //output: 0.300000000000007 double d = Math.rint(c*10) / 10; System.out.println(d); //output: 0.3 } } Why I have to use Math.rint to get 0.3? Has it do to with the type double or with Java?
3 Respostas
+ 1
Not necessarily, usually double precision is used for large numbers only
0
Thank you for the fast answer. So I should every time use this math method when I use double?
0
But in my case I don't have large. The code above belongs to my program:
https://code.sololearn.com/c5C9tWQq8Qlm/?ref=app It did'nt worked without using Math.rint ().