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

    package text;
    
    import java.awt.print.Book;
    import java.lang.reflect.Array;
    import java.security.Principal;
    import java.sql.Date;
    import java.text.DecimalFormat;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Arrays;
    
    import javax.xml.crypto.Data;
    
    public class text1 {
        // TODO Auto-generated method stub
        static public void SimgleFormat(String pattem, double value){
            DecimalFormat myFormat = new DecimalFormat(pattem);
            String output = myFormat.format(value);
            System.out.println(value + " " + pattem + " " + output);
        }
        
        static public void UseApplypattenMethodFormat(String pattem , double value){
            DecimalFormat myFormat = new DecimalFormat(pattem);
            myFormat.applyPattern(pattem);
            System.out.println(value + " " + " " + myFormat.format(value));
        }
        
        public static void main(String[] args) {
            SimgleFormat("###,###,###.###", 123456.789);
            SimgleFormat("00000000.####kg", 123456.789);
            SimgleFormat("000000.000", 123.78);
            UseApplypattenMethodFormat("#.###%",0.789);
            UseApplypattenMethodFormat("###.##", 123456.789);
            UseApplypattenMethodFormat("0.00u2030", 0.789);
        }
    }

     1 package text;
     2 
     3 import java.awt.print.Book;
     4 import java.lang.reflect.Array;
     5 import java.security.Principal;
     6 import java.sql.Date;
     7 import java.text.DecimalFormat;
     8 import java.text.SimpleDateFormat;
     9 import java.util.ArrayList;
    10 import java.util.Arrays;
    11 
    12 import javax.xml.crypto.Data;
    13 
    14 public class text1 {
    15     // TODO Auto-generated method stub
    16     public static void main(String[] args) {
    17         DecimalFormat myFormat = new DecimalFormat();
    18         myFormat.setGroupingSize(2);
    19         String output1 = myFormat.format(123465.789);
    20         System.out.println("分组后的结果 "+ output1);
    21         myFormat.setGroupingUsed(false);
    22         String output2 = myFormat.format(123456.789);
    23         System.out.println("未分组的结果 "+ output2);
    24     }
    25 }
    View Code
  • 相关阅读:
    谈谈对程序猿的管理
    OFMessageDecoder 分析
    [LeetCode-21]Construct Binary Tree from Preorder and Inorder Traversal
    leetcode第一刷_Rotate Image
    [二次开发]dede文章页面怎样显示作者的头像
    MapReduceTopK TreeMap
    安卓3d引擎
    LeetCode::Sort List 具体分析
    杨帆之工作日志-2014.6.24
    CF1109F Sasha and Algorithm of Silence's Sounds
  • 原文地址:https://www.cnblogs.com/dulute/p/10557687.html
Copyright © 2011-2022 走看看