Java 使用十进制格式将双精度舍入到小数点后两位
尝试将一个数字(110.99)四舍五入,去掉一个百分比,然后将10改为99.90 目前我正在使用Java 使用十进制格式将双精度舍入到小数点后两位,java,format,double,decimalformat,Java,Format,Double,Decimalformat,尝试将一个数字(110.99)四舍五入,去掉一个百分比,然后将10改为99.90 目前我正在使用 public static String GetDiscountedPrice(double OriginalPrice, int PercentDiscount) { DecimalFormat df = new DecimalFormat("##.##"); double roundedNumber = (OriginalPrice * (PercentDiscount / 1
public static String GetDiscountedPrice(double OriginalPrice, int PercentDiscount)
{
DecimalFormat df = new DecimalFormat("##.##");
double roundedNumber = (OriginalPrice * (PercentDiscount / 100.0));
roundedNumber = (OriginalPrice - roundedNumber);
//roundedNumber = Math.round(((roundedNumber * 100.0) / 100.0));
roundedNumber = Double.valueOf(df.format(roundedNumber));
String discountedPrice = String.valueOf(roundedNumber);
return discountedPrice;
}
我的问题是我一直得到99.89的值
当我将DecimalFormat更改为(“##.#”)时,它输出99.9。我需要99.90分
如果不在结尾处硬编码“0”,我该如何执行此操作
谢谢