Basically, I don't understand why the code below will output 434 when 4.35 * 100 = 435.0 which is converted to the int of 435, right?
What is the simple explanation for this and is this an issue which crops up often?
How would you get around this?
public class RoundOffDemo {
public static void main(String[] args) {
double price = 4.35;
int cents = (int) (100 * price); // Should be 435
System.out.println(cents); // Prints 434!
}
}