JAVA對金額格式化

原貼地址:https://bbs.csdn.net/topics/390418233

顯示結果爲小數點後保留2位,小數點前每3位一個逗號。

public String getDecimalFormat(String str){
		Integer initValue=0;
		String outStr = "";
		if(str!=null&&!"".equals(str.trim())){
			initValue=Integer.parseInt(str);
			Integer yuanValue=initValue/100;
			DecimalFormat   fmt   =   new   DecimalFormat("##,###,###,###,###.00");  
			double d;
			try {
				d = Double.parseDouble(String.valueOf(yuanValue));
				outStr = fmt.format(d);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return outStr;
	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章