import java.text.DecimalFormat;
static DecimalFormat df4 = new DecimalFormat("#.0000");
Double a = 3591000;
Double d = a/10000000;
String str = df4.format(d);
Run Code Online (Sandbox Code Playgroud)
在这里我期望0.3591,但是df4.format在小数点之前删除0。印刷.3591
使用
static DecimalFormat df4 = new DecimalFormat("0.0000")
Run Code Online (Sandbox Code Playgroud)
根据文档:
#:零表示缺席
虽然0没有。