Question: Consider the following code segment. double purchase = 19.93; double payment = 20.00; double change = payment - purchase; System.out.println(change); The code segment prints the

Consider the following code segment.
double purchase = 19.93;
double payment = 20.00;
double change = payment - purchase;
System.out.println(change);

The code segment prints the change as 0.07000000000000028. Explain why. Give a recommendation to improve the code so that users will not be confused.

Step by Step Solution

3.49 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Java double is utilized to address floating point or decimal numbers It utilizes 64 bits to store a ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Concepts Late Objects Questions!