This question already has an answer here:
- Float comparison mismatch 2 answers
I'm trying to find the total cost of delivery charge base on parcel weight.
Why when I put anything more than 2.5 it'll came out as 2 answers?
E.g:
Please enter parcelweight
3
The charge is 8.55
The charge is 7.3500000000000005
The corresponding code is:
if(parcelweight < 2.5)
{
System.out.println("The charge is" +parcelweight*3.5);
}
else {
if((parcelweight >=2.5 && parcelweight <=5));
{
System.out.println("The charge is" +parcelweight*2.85);
}
if(parcelweight > 5);
{
System.out.println("The charge is" +parcelweight*2.45);
}
}
Aucun commentaire:
Enregistrer un commentaire