2017-06-28 82 views
0
import java.text.DecimalFormat; 
static DecimalFormat df4 = new DecimalFormat("#.0000"); 

Double a = 3591000; 
Double d = a/10000000; 
String str = df4.format(d); 

這裏我期望0.3591,但df4.format在小數點前刪除0。印刷0.3591DecimalFormat格式在小數點前刪除前導0

+0

如何獲得0.3591 – sks

+1

因此,下一個理性的事情是閱讀文檔以瞭解您的錯誤並修復它。 https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html –

回答

1

使用

static DecimalFormat df4 = new DecimalFormat("0.0000") 

按照documentation

#:零顯示爲不存在

0沒有。

+0

其工作非常感謝你。 – sks

+0

非常感謝! – Markus