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");
}
从我得到的服务中305lb 0.050469oz
,但是当它转换它的显示305lbs 0.1oz
时,它应该只显示 305 磅。