DecimalFormat pattern

≡放荡痞女 提交于 2019-11-29 02:07:42
Pieter
Symbol  Location    Localized?  Meaning
0       Number      Yes         Digit
#       Number      Yes         Digit, zero shows as absent 

From: http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html

So # is not shown when there is no number. The leading 0 means there will be at least 1 digit before the decimal separator.

# will put a digit only if it is not a leading zero. 0 will put a digit even if it is a trailing zero. You could use zeros in front, too, if you wanted a fixed number of digits printed.

With the zero before the dp, small numbers like 0.23 will be displayed as 0.23. Without it you will not get the leading zero, so it is just displayed as .23. If you have a spreadsheet like excel you can check this there too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!