This question already has an answer here:
- Moving decimal places over in a double 9 answers
I recently tested something out that I heard using the following code
public static void main(String[] args) {
double x = 4.35 * 100;
System.out.println(x);
}
.
I am interested as to why this produces 434.99999999999994 rather than 435.0 . Thanks
when you type
x is not stored as-is. It is stored in a approaching form (probably 4.349999999 in this case).
If you want exact result, please use BigDecimal.