zoukankan      html  css  js  c++  java
  • DecimalFormat 数字格式化

    字符串数字的格式

    import java.text.*;
    
    class DecimalFormatDemo {
        static public void main(String[] args) {
            customFormat("###,###.###", 123456.789);
            customFormat("###.##", 123456.789);
            customFormat("000000.000", 123.78);
            customFormat("$###,###.###", 12345.67);
        }
    
        /**
         * Prints a double value formatted according to a given pattern.
         */
        static public void customFormat(String pattern, double value) {
            DecimalFormat myFormatter = new DecimalFormat(pattern);
            String output = myFormatter.format(value);
            System.out.println(value + "  " + pattern + "  " + output);
        }
    }
    123456.789  ###,###.###  123,456.789
    123456.789  ###.##  123456.79
    123.78  000000.000  000123.780
    12345.67  $###,###.###  $12,345.67
    Output:
     
    如有错误,恳求读者指出,发送到wu13213786609@outlook.com。
  • 相关阅读:
    centos7安装kde桌面
    centos7安装NVIDIA驱动
    15日报
    11日报
    14日报
    奖励加分
    课程建议
    13日报
    12日报
    每日总结1213
  • 原文地址:https://www.cnblogs.com/WLCYSYS/p/15250290.html
Copyright © 2011-2022 走看看