我想返回一个带 2 个小数位的双精度数(即 123.00)。以下是部分代码。输出始终为 123.0。如何获得两位小数?
public static double getPrice(){
double price = Double.valueOf(showInputDialog("Stock's price : "));
DecimalFormat rounded = new DecimalFormat("###.00");
double newPrice = Double.valueOf(rounded.format(price));
System.out.println(newPrice);
return newPrice;
}