Double类型输出的问题
double a = 2.0;
double b = 3.0;
System.out.println(a/b);
此时输出为0.6666666666666666
我想让它只输出两个有效为即为0.67,该怎么写呢?
------解决方案--------------------double a = 2.0;
double b = 3.0;
long num = Math.round((a/b)*100);
System.out.println(num/100.0);
------解决方案--------------------NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(a/b));