Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用十进制格式将双精度舍入到小数点后两位_Java_Format_Double_Decimalformat - Fatal编程技术网

Java 使用十进制格式将双精度舍入到小数点后两位

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

尝试将一个数字(110.99)四舍五入,去掉一个百分比,然后将10改为99.90

目前我正在使用

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”,我该如何执行此操作

谢谢