我正在开发会计管理应用程序,我需要存储有关交易的信息。由于交易金额或总金额可能超过17位数,我希望它们以纯文本或普通Decimal
格式显示。但在Java
中,一个大数字显示为指数格式。我已经在Google
和Stackoverflow
上搜索了它以获得解决方案,但没有获得任何合适的解决方案。我试过这些:
double number = 123456789123456789.987654;
System.out.println("" + number);
System.out.println(number);
System.out.println(String.format("%.3f", number));
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(3);
System.out.println(df.format(number));
DecimalFormat df1 = new DecimalFormat("#.##");
System.out.println(df1.format(number));
System.out.println(new BigDecimal(number).stripTrailingZeros().setScale(3));
输出结果为:
1.23456789123456784E17
1.23456789123456784E17
123456789123456784.000
123456789123456784
123456789123456784
123456789123456784.000
我希望输出为 123456789123456789.988
我怎样才能获得那样的输出?