集册 Java实例教程 使用自定义格式$ ###,###。###格式化双精度值

使用自定义格式$ ###,###。###格式化双精度值

欢马劈雪     最近更新时间:2020-01-02 10:19:05

577
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用自定义格式$ ###,###。###格式化双精度值
/** n o w    j a v a  . c o m 提供 **/

import java.text.*;


public class DecimalFormatDemo {


    static public void customFormat(String pattern, double value) {

        DecimalFormat myFormatter = new DecimalFormat(pattern);

        String output = myFormatter.format(value);

        System.out.println(value + "  " + pattern + "  " + output);

    }


    static public void main(String[] args) {


        customFormat("###,###.###", 123456.789);

        customFormat("###.##", 123456.789);

        customFormat("000000.000", 123.78);
        /* from 
        时代Java公众号 - nowjava.com*/

        customFormat("$###,###.###", 12345.67);

    }

}


展开阅读全文