public static double convertWeight(String value, String value2) {
double lbs = 0;
double ounces = 0;
if (!value.equals("")) {
lbs = Double.parseDouble(value);
}
if (!value2.equals("")) {
ounces = Double.parseDouble(value2) * 0.062500;
}
double grams = (lbs + ounces) / 0.0022046;
return grams;
}
I have this piece of code, where at sometimes i get pounds or oz value empty
. The above piece of code works fine, but i am not happy the way i have written the code. Can anyone tell me a better alternate way.
I have to convertWeight
. So from my service i get sometimes values or sometimes just empty strings. If its empty i ensure that i pass lbs or ounces "Zero
" converWeight(value1, value2);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…