java的NumberFormat使用

		try {
			NumberFormat formater = NumberFormat.getNumberInstance();
			formater.setMaximumFractionDigits(2);
			formater.setMinimumFractionDigits(2);
			ResultSet rs = GuoJiaBiaoZhunSqlServerConn.execSql(sql, false);
			while(rs.next()){
				DailyReportData rowData = new DailyReportData();
				String area = StrUtils.secTrim(rs.getString(1));
				for(int i = 0;i<summaryList.size();i++){
					if(summaryList.get(i).getDay().indexOf(area)>=0){
						rowData = summaryList.get(i);
						break;
					}
				}
				rowData.setJan(rs.getString(2)!=null?formater.format(rs.getDouble(2)):rs.getString(2));
				rowData.setFeb(rs.getString(3)!=null?formater.format(rs.getDouble(3)):rs.getString(3));
				rowData.setMar(rs.getString(4)!=null?formater.format(rs.getDouble(4)):rs.getString(4));
				rowData.setApr(rs.getString(5)!=null?formater.format(rs.getDouble(5)):rs.getString(5));
				rowData.setMay(rs.getString(6)!=null?formater.format(rs.getDouble(6)):rs.getString(6));
				rowData.setJun(rs.getString(7)!=null?formater.format(rs.getDouble(7)):rs.getString(7));
				rowData.setJul(rs.getString(8)!=null?formater.format(rs.getDouble(8)):rs.getString(8));
				rowData.setAug(rs.getString(9)!=null?formater.format(rs.getDouble(9)):rs.getString(9));
				rowData.setSep(rs.getString(10)!=null?formater.format(rs.getDouble(10)):rs.getString(10));
				rowData.setOct(rs.getString(11)!=null?formater.format(rs.getDouble(11)):rs.getString(11));
				rowData.setNov(rs.getString(12)!=null?formater.format(rs.getDouble(12)):rs.getString(12));
				rowData.setDec(rs.getString(13)!=null?formater.format(rs.getDouble(13)):rs.getString(13));
				rowData.setAtrr1(rs.getString(14)!=null?formater.format(rs.getDouble(14)):rs.getString(14));
				//变幅
				rowData.setAtrr2(rs.getString(15)!=null?formater.format(rs.getDouble(15)):rs.getString(15));
				rowData.setAtrr3(rs.getString(16)!=null?formater.format(rs.getDouble(16)):rs.getString(16));
				rowData.setAtrr4(rs.getString(17)!=null?formater.format(rs.getDouble(17)):rs.getString(17));
				rowData.setAtrr5(rs.getString(18)!=null?formater.format(rs.getDouble(18)):rs.getString(18));

			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

你可能感兴趣的:(format)