java怎样精确小数点???
.1.(double) (Math.round(sd3*10000)/10000.0);
这样为保持4位
(double) (Math.round(sd3*100)/100.0);
这样为保持2位.
2.另一种办法
import java.text.DecimalFormat;
DecimalFormat df2 = new DecimalFormat(“###.00”);
DecimalFormat df2 = new DecimalFormat(“###.000”);
System.out.println(df2.format(doube_var));
第一个为2位,第二个为3位.
Java中如何将5830变为5.830?小数点向前移动三位。
@Test
public void test(){
int i = 5830;
DecimalFormat decimalFormat = new DecimalFormat(“#.000”);
System.out.println(decimalFormat.format(Integer.valueOf(i).doubleValue()/1000));
}
java如何把小数点向前移两位?如7454.43823
这个只能转换成字符串再移动小数点了,直接使用0.1的乘法,包括除以10什么的,会有计算机舍入误差,你多打一些小数位数,后面的不准确值就能看出来了