import java.util.Scanner;
import java.text.DecimalFormat;
public class HelloWorld{
public static void main(String [] args ){
Scanner input = new Scanner(System.in);
System.out.println("请输入第一个数的值:");
double s = input.nextInt();
double res = (s-32)*5/9.0;
System.out.println(res);
DecimalFormat df = new DecimalFormat("0.00");
double numA = 8.2;
int numB = 2;
double result = numA - numB;
System.out.println(df.format(result));
System.out.println(df.format(res));
}
}
如何保留两位小数
import java.text.DecimalFormat;
public class Test{
public static void main(String []args){
//创建DecimalFormat的对象
DecimalFormat df=new DecimalFormat("0.00");
double numA=8.2;
int numB=2;
double result =numA-numB;
//调用了format()方法
System.out.println( df.format( result ) ); //调用了DecimalFormat类中的format方法,帮助我们进行格式化数字的
}
}