new DecimalFormat.(##0.####).format(1234.5678)

package test;

import java.text.DecimalFormat;

public class test{
    public static void main(String[] args){
       
        System.out.println(new DecimalFormat("#0.###E0").format(1234566700));
        System.out.println(new DecimalFormat("#0.###E0").format(123456670));
        System.out.println(new DecimalFormat("#0.###E0").format(12345667));
        System.out.println(new DecimalFormat("#0.###E0").format(1234566.7));
        System.out.println(new DecimalFormat("#0.###E0").format(123456.67));
        System.out.println(new DecimalFormat("#0.###E0").format(12345.667));
        System.out.println(new DecimalFormat("#0.###E0").format(1234.5667));
        System.out.println(new DecimalFormat("#0.###E0").format(123.45667));
        System.out.println(new DecimalFormat("#0.###E0").format(12.345667));
        System.out.println(new DecimalFormat("#0.###E0").format(1.2345667));
        System.out.println(new DecimalFormat("#0.###E0").format(0.12345667));
        System.out.println(new DecimalFormat("#0.###E0").format(0.012345667));
        System.out.println(new DecimalFormat("#0.###E0").format(0.0012345667));
        System.out.println(new DecimalFormat("#0.###E0").format(0.00012345667));
        
        System.out.println("-------------------------------------------");
        
        System.out.println(new DecimalFormat("##0.###E0").format(1234566700));
        System.out.println(new DecimalFormat("##0.###E0").format(123456670));
        System.out.println(new DecimalFormat("##0.###E0").format(12345667));
        System.out.println(new DecimalFormat("##0.###E0").format(1234566.7));
        System.out.println(new DecimalFormat("##0.###E0").format(123456.67));
        System.out.println(new DecimalFormat("##0.###E0").format(12345.667));
        System.out.println(new DecimalFormat("##0.###E0").format(1234.5667));
        System.out.println(new DecimalFormat("##0.###E0").format(123.45667));
        System.out.println(new DecimalFormat("##0.###E0").format(12.345667));
        System.out.println(new DecimalFormat("##0.###E0").format(1.2345667));
        System.out.println(new DecimalFormat("##0.###E0").format(0.12345667));
        System.out.println(new DecimalFormat("##0.###E0").format(0.012345667));
        System.out.println(new DecimalFormat("##0.###E0").format(0.0012345667));
        System.out.println(new DecimalFormat("##0.###E0").format(0.00012345667));
        
System.out.println("-------------------------------------------");
        
        System.out.println(new DecimalFormat("##0.####E0").format(1234566700));
        System.out.println(new DecimalFormat("##0.####E0").format(123456670));
        System.out.println(new DecimalFormat("##0.####E0").format(12345667));
        System.out.println(new DecimalFormat("##0.####E0").format(1234566.7));
        System.out.println(new DecimalFormat("##0.####E0").format(123456.67));
        System.out.println(new DecimalFormat("##0.####E0").format(12345.667));
        System.out.println(new DecimalFormat("##0.####E0").format(1234.5667));
        System.out.println(new DecimalFormat("##0.####E0").format(123.45667));
        System.out.println(new DecimalFormat("##0.####E0").format(12.345667));
        System.out.println(new DecimalFormat("##0.####E0").format(1.2345667));
        System.out.println(new DecimalFormat("##0.####E0").format(0.12345667));
        System.out.println(new DecimalFormat("##0.####E0").format(0.012345667));
        System.out.println(new DecimalFormat("##0.####E0").format(0.0012345667));
        System.out.println(new DecimalFormat("##0.####E0").format(0.00012345667));
        
        System.out.println("-------------------------------------------");
        
        System.out.println(new DecimalFormat("##0.###E0").format(1));
        System.out.println(new DecimalFormat("##0.###E0").format(10));
        System.out.println(new DecimalFormat("##0.###E0").format(100));
        System.out.println(new DecimalFormat("##0.###E0").format(1000));
        System.out.println(new DecimalFormat("##0.###E0").format(10000));
        System.out.println(new DecimalFormat("##0.###E0").format(100000));
        System.out.println(new DecimalFormat("##0.###E0").format(1000000));
        System.out.println(new DecimalFormat("##0.###E0").format(10000000));
        System.out.println(new DecimalFormat("##0.###E0").format(100000000));
        
System.out.println("-------------------------------------------");
        
        System.out.println(new DecimalFormat("##0.###").format(1));
        System.out.println(new DecimalFormat("##0.###").format(10));
        System.out.println(new DecimalFormat("##0.###").format(100));
        System.out.println(new DecimalFormat("##0.###").format(1000));
        System.out.println(new DecimalFormat("##0.###").format(10000));
        System.out.println(new DecimalFormat("##0.###").format(100000));
        System.out.println(new DecimalFormat("##0.###").format(1000000));
        System.out.println(new DecimalFormat("##0.###").format(10000000));
        System.out.println(new DecimalFormat("##0.###").format(100000000));
        
System.out.println("-------------------------------------------");
        
		System.out.println(new DecimalFormat("##0.###").format(0.1));
        System.out.println(new DecimalFormat("##0.###").format(0.11));
        System.out.println(new DecimalFormat("##0.###").format(0.101));
        System.out.println(new DecimalFormat("##0.###").format(0.1001));
        System.out.println(new DecimalFormat("##0.###").format(0.10001));
        System.out.println(new DecimalFormat("##0.###").format(0.100001));
        System.out.println(new DecimalFormat("##0.###").format(0.1000001));
        System.out.println(new DecimalFormat("##0.###").format(0.10000001));
        System.out.println(new DecimalFormat("##0.###").format(0.100000001));
        System.out.println(new DecimalFormat("##0.###").format(0.1000000001));
    }
}

结果是:

12.346E8
1.2346E8
12.346E6
1.2346E6
12.346E4
1.2346E4
12.346E2
1.2346E2
12.346E0
1.2346E0
12.346E-2
1.2346E-2
12.346E-4
1.2346E-4
-------------------------------------------
1.23457E9
123.457E6
12.3457E6
1.23457E6
123.457E3
12.3457E3
1.23457E3
123.457E0
12.3457E0
1.23457E0
123.457E-3
12.3457E-3
1.23457E-3
123.457E-6
-------------------------------------------
1.234567E9
123.4567E6
12.34567E6
1.234567E6
123.4567E3
12.34567E3
1.234567E3
123.4567E0
12.34567E0
1.234567E0
123.4567E-3
12.34567E-3
1.234567E-3
123.4567E-6
-------------------------------------------
1E0
10E0
100E0
1E3
10E3
100E3
1E6
10E6
100E6
-------------------------------------------
1
10
100
1000
10000
100000
1000000
10000000
100000000
-------------------------------------------
0.1
0.11
0.101
0.1
0.1
0.1
0.1
0.1
0.1
0.1

 

你可能感兴趣的:(Java)