2011년 10월 18일 화요일

JAVA_코딩 테크닉_자바 백분율 예제

for (Iterator<Object> i = tArr.iterator();i.hasNext();)
{
hm = (HashMap<String, Object>)i.next();
tempResultTotal += Double.parseDouble(String.valueOf(hm.get("RESULT_TOTAL")));
}

=========================================================================


HashMap map = (HashMap)itr.next();


resultPer = Double.parseDouble(map.get("RESULT_PER").toString());
planPer = Double.parseDouble(map.get("PLAN_PER").toString());

if(resultPer < 1)
{
resultPer = 0*0.01d;
}

if(planPer > 0)
{
resultPerTotal = resultPer / planPer;
bDecimal = new BigDecimal(resultPerTotal).setScale(2, BigDecimal.ROUND_HALF_UP);
resultPerTotal = Double.parseDouble(bDecimal.toString());
}
else
{
planPer = 0*0.01d;
}


tempResult = Double.parseDouble(String.valueOf(map.get("RESULT_TOTAL")));

if(tempResultTotal > 0)
{
tempResult = tempResult / tempResultTotal * 100;
bDecimal = new BigDecimal(tempResult).setScale(2, BigDecimal.ROUND_HALF_UP);
tempResult = Double.parseDouble(bDecimal.toString());


}
else
{
tempResult = 0*0.01d;
}


tempPlan = Double.parseDouble(String.valueOf(map.get("PLAN_PER_TOTAL")));
if(tempPlan > 0)
{
tempPeref = tempResult / tempPlan ;
bDecimal = new BigDecimal(tempPeref).setScale(2, BigDecimal.ROUND_HALF_UP);
tempPeref = Double.parseDouble(bDecimal.toString());
}

댓글 없음:

댓글 쓰기