public void priceMaker(float perc) {
float distance = (float) dist.getValue();
if (distance >= (float) 75.0) {
switch (distance) {
case 5.0:
float f_5 = (float) (80.0 * 5.0 * perc);
label_f_5_result.setText("Rs.80 * 5 * " + perc + "( risk factor % ) = " + f_5);
label_apx_delv_fee_result.setText("Rs." + f_5);
}
}
}
I'm retrieving a distance value (like 1.5, 5, 4.3 in kilometers) from a jSpinner in my GUI. I have already changed the jSpinner model to [Number]>>(float). However I keep getting an IDE error even after I cast the calculations to float
type:
possible lossy conversion from float to int error
I'm still a Java beginner and I couldn't find a solution. However, if I change distance
from float
to int
the error disappears but I want float values because a distance won't be a roundup.