// 克 到 磅和盎司
public static String convertGramsToPoundsAndOunces(String grams) {
double weightInKG = Double.parseDouble(grams) / 1000;
double pounds = weightInKG / 0.45359237;
double lbs = Math.floor(pounds);
double fraction = (pounds - lbs) * 16;
return String.valueOf(Math.round(lbs) + "lbs" + " " + String.format("%.1f", new BigDecimal(fraction)) + "oz");
}
// 磅和盎司 自 克
public static double convertPoundsToGrams(String pounds, String oz) {
double lbs = 0;
double ounces = 0;
double grams = 0;
try {
if (pounds != null && pounds.trim().length() != 0) {
lbs = Double.parseDouble(pounds);
}
if (oz != null && oz.trim().length() != 0) {
ounces = Double.parseDouble(oz) * 0.062500;
}
grams = (lbs + ounces) / 0.0022046;
return grams;
} catch (NumberFormatException nfe) {
System.err.println("Invalid input.");
}
return grams;
}
我尝试将磅和盎司转换为克,并通过转换克来显示相同的磅和盎司。
我输入 1 磅和 0.9 盎司,它们转换回克,但是当我将克转换回磅和盎司时,我得到 1 磅和 1.1 磅... [ 0.2 ounces is getting increased each time
]