My apologies if that was asked somewhere, but I couldn't find anything that would help me. This is part of my larger program when I want to add numbers and display them, but when I encountered number 0.6
output is not "accurate". I want to display them exactly to one decimal point. How I can achieve this ?
Source Code:
public class NumberTest {
public static void main(String[] args){
double n = 0.6;
double sum = 0.0;
for(int i = 0; i < 10; i++){
System.out.println(sum);
sum += n;
}
}
}
Output:
0.0
0.6
1.2
1.7999999999999998
2.4
3.0
3.6
4.2
4.8
5.3999999999999995