1.如何将数字输出为每三位逗号分隔的格式,例如“1,234,467”?   

 1 package com.Gxjun.problem;
 2 
 3 import java.text.DecimalFormat;
 4 import java.util.Scanner;
 5 
 6 
 7 /*
 8  * 如何将数字输出为每三位逗号分隔的格式,
 9  * 例如“1,234,467”?
10  * */
11 
12  public class FloatDirve {
13   
14   public static void main(String args []){
15      Scanner  reader = new Scanner(System.in);
16       while(reader.hasNext()){
17         System.out.println(funcFormat(reader.nextDouble()));
18       }
19    }
20   /* 使用一个方法来处理这个格式 */
21   public static String funcFormat(double doub){
22     String str="###";
23     int len=String.valueOf(doub).length();
24     for(int i=3;i<=len;i+=3){
25          str+=",###";
26     }
27     DecimalFormat decf = new DecimalFormat();
28     decf.applyPattern(str);
29    return decf.format(doub);
30   }
31 }
View Code

相关文章:

  • 2021-07-01
  • 2022-02-28
  • 2021-10-01
  • 2022-02-06
  • 2022-12-23
  • 2021-08-21
  • 2022-02-02
猜你喜欢
  • 2022-01-07
  • 2021-10-03
  • 2021-12-11
  • 2021-10-24
  • 2021-07-24
  • 2021-07-27
  • 2022-12-23
相关资源
相似解决方案