【问题标题】:DecimalFormat format is removing leading 0 before decimal point [duplicate]DecimalFormat 格式正在删除小数点前的前导 0 [重复]
【发布时间】:2017-06-28 21:43:31
【问题描述】:
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。打印 .3591

【问题讨论】:

标签: java jakarta-ee


【解决方案1】:

使用

static DecimalFormat df4 = new DecimalFormat("0.0000")

根据documentation

# : 零表示不存在

0 没有。

【讨论】:

  • 它的工作非常感谢你。
  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
  • 1970-01-01
  • 2018-02-15
  • 2012-05-03
相关资源
最近更新 更多