【问题标题】:Java Decimal Format results with trailing zeros带有尾随零的 Java 十进制格式结果
【发布时间】:2015-10-22 17:08:06
【问题描述】:

这是我的代码:

import java.text.DecimalFormat;

public class asd {
    public static void main(String args[]) {
        DecimalFormat d = new DecimalFormat("#00.00");
        System.out.println(d.format(0250));
    }
}

它给出168.00 作为答案。这不是我所期待的答案(即 250.00)。为什么会这样?

【问题讨论】:

    标签: java decimalformat


    【解决方案1】:

    因为0250 中的前导0 使它成为八进制。删除前导 0。喜欢,

    public static void main(String args[]) {
        DecimalFormat d = new DecimalFormat("#00.00");
        System.out.println(d.format(250));
    }
    

    另请参阅this question,了解为什么这是八进制表示法的语法。

    【讨论】:

    • 链接加一个
    猜你喜欢
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 2012-06-28
    • 2011-04-28
    • 2016-11-13
    • 1970-01-01
    相关资源
    最近更新 更多