码迷,mamicode.com
首页 > 其他好文 > 详细

review18

时间:2018-08-05 14:30:34      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:使用   运行   模式   直接   str   static   string类   3.3   view   

数字格式化

程序可以直接使用String类调用format方法对数字进行格式化。

format方法中的“格式化模式”是一个用双引号括起的字符序列(字符串),该字符序列的字符由格式符和普通字符所构成。代码展示如下所示:

public class Test05 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String s1 = String.format("%.2f", 3.1415926);
        System.out.println(s1);
        String s2 = String.format("%d元%3.3f公斤%d台", 888, 999.7766, 123);
        System.out.println(s2);
    }

}

运行结果如下所示:

技术分享图片

 

review18

标签:使用   运行   模式   直接   str   static   string类   3.3   view   

原文地址:https://www.cnblogs.com/liaoxiaolao/p/9425068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!