我正在尝试使用 String.format 来获取逗号分隔、零填充的 double 。 我正在使用:
"%0,9.2f", unitPrice
单价是双倍。例如,当 unitPrice 为 44.99 时,当我想要 00,044.99 时,我会得到 000044.99。如果单价是 4499,我会得到 04,499.00。
最佳答案
您可以使用 DecimalFormat
(NumberFormat
的具体子类,用于格式化十进制数字。它具有多种功能,旨在能够在任何区域设置中解析和格式化数字,包括对西方、阿拉伯和印度数字的支持 )就像
DecimalFormat df = new DecimalFormat("00,000.00");
System.out.println(df.format(44.99));
System.out.println(df.format(4499));
输出是(根据要求)
00,044.99
04,499.00
关于java - 如何在java中用逗号分隔零填充的String.format double ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533991/