集册 Java实例教程 格式化双精度型值

格式化双精度型值

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

411
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
格式化双精度型值
/* 
*来 自
 N o w  J a v a  . c o m
*/

import java.util.Calendar;

import java.util.Locale;


public class TestFormat {


    public static void main(String[] args) {

        long n = 461012;

        System.out.format("%d%n", n);

        System.out.format("%08d%n", n);

        System.out.format("%+8d%n", n);

        System.out.format("%,8d%n", n);

        System.out.format("%+,8d%n%n", n);


        double pi = Math.PI;

        System.out.format("%f%n", pi);

        System.out.format("%.3f%n", pi);/** from N  o w  J a v a . c o m**/

        System.out.format("%10.3f%n", pi);

        System.out.format("%-10.3f%n", pi);

        System.out.format(Locale.FRANCE, "%-10.4f%n%n", pi);


        Calendar c = Calendar.getInstance();

        System.out.format("%tB %te, %tY%n", c, c, c);

        System.out.format("%tl:%tM %tp%n", c, c, c);

        System.out.format("%tD%n", c);

    }

}


展开阅读全文