• 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
  • 相关阅读:
    vue学习之遇见的问题
    npm install 报错
    git错误
    mysql解压缩方式安装和彻底删除
    webpack 报错:Module build failed: Unknown word (1:1)
    简单分析Java的HashMap.entrySet()的实现
    spring的四种依赖注入的方式
    探秘static——类不需实例化就能用?
    【转】java并发编程:synchronized
    【转】我们为什么要使用AOP?
  • 原文地址:https://www.cnblogs.com/dulute/p/10557687.html
Copyright © 2020-2023  润新知