Java JOptionPane输出双精度到小数点后2位:

Java JOptionPane输出双精度到小数点后2位:,java,Java,所以,我已经完成了另一个课程,并试图让它看起来更“漂亮”。我对每个问题和选择都使用了JOptionPane,但是输出…是否有一种方法可以使用J-pane将答案输出到小数点后2位,就像我使用System.ou.print一样 仅发布一种方法的部分代码 public static void Celsius() //First method used within Start to convert Celsius to Fahrenheit { double conve

所以,我已经完成了另一个课程,并试图让它看起来更“漂亮”。我对每个问题和选择都使用了JOptionPane,但是输出…是否有一种方法可以使用J-pane将答案输出到小数点后2位,就像我使用System.ou.print一样

仅发布一种方法的部分代码

public static void Celsius()  

 //First method used within Start to convert Celsius to Fahrenheit       
{

    double converted;
    double temperature;
    //user inputs temperature to be converted 
    temperature = Double.parseDouble(JOptionPane.showInputDialog(null,
            "Please enter the temperature in Celsius and press 'Ok'",
            "You selected Celsius to Fahrenheit",
            JOptionPane.INFORMATION_MESSAGE));                                                      
    converted = 9/5.0*temperature+32;  
    //outputs converted temperature
    System.out.print("The converted temperature in Fahrenheit = ");
    System.out.printf(" %.2f", converted);         
    System.out.println(" degrees Fahrenheit");
}
您正在寻找(另请参见)

您正在寻找(另请参见)


谢谢也许我需要等待一点然后再尝试这个,因为它看起来有点超出我们的类目前。我会试着把我的头绕在它周围,并希望在将来使用它。谢谢!也许我需要等待一点然后再尝试这个,因为它看起来有点超出我们的类目前。我会尝试着用我的头脑去理解它,并希望在将来使用它。
DecimalFormat df = new DecimalFormat("#.##");
String formatted = df.format(2.456345); 
JOptionPane.showMessageDialog(null, "Result: " + formatted);   // shows 2.46