java中价格的数字中间有逗号的格式化

  1. public class DecimalFormatTool {  
  2.       
  3.     //每3位中间添加逗号的格式化显示  
  4.     public static String getCommaFormat(BigDecimal value){  
  5.         return getFormat(",###.##",value);  
  6.     }  
  7.       
  8.     //自定义数字格式方法  
  9.     public static String getFormat(String style,BigDecimal value){  
  10.         DecimalFormat df = new DecimalFormat();  
  11.         df.applyPattern(style);// 将格式应用于格式化器  
  12.         return df.format(value.doubleValue());  
  13.     }  
  14.       
  15.     public static void main(String[] args) {  
  16.         System.out.println(DecimalFormatTool.getCommaFormat(new BigDecimal(0.5)));  
  17.     }  
  18.       
相关文章
相关标签/搜索