【问题标题】:formatting double and float once and for all in jsf2 application在jsf2应用程序中一劳永逸地格式化double和float
【发布时间】:2013-05-01 11:04:59
【问题描述】:

我做了很多操作,用数字计算(尤其是双精度(#0.00))

我问是否有办法一劳永逸地格式化这些数字 我暂时使用这个转换器来处理每个双精度:

<f:convertNumber pattern="#0.00" />

提前谢谢你

【问题讨论】:

    标签: java formatting numbers floating


    【解决方案1】:

    试试这个:

    DecimalFormat df2 = new DecimalFormat( "#0.00" );
    double d = 122.00;
    System.out.println(df2.format(d));
    double dou = new Double(df2.format(d)).doubleValue();
    System.out.println(dou);
    

    输出:

    122.00
    122.0
    

    如果您想要两位数,即使小数点后的零也可以打印为Stringdouble 122.00 的值是 12.0。如果你分配 double dd = 122.00 并打印它会给出输出 122.0

    【讨论】:

    • 它返回字符串 bud 我想要双倍
    • 我想要逗号后面的两位数,即使是 0
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 2016-03-20
    • 2015-09-25
    • 2016-07-20
    • 2017-06-16
    • 1970-01-01
    相关资源
    最近更新 更多