Code example for BigDecimal

Methods: divide

0
	 * @return 
	 */ 
	public static Exam  sortExamMark(Exam exam){
		List<ExamMark> ems = exam.getExamMarks();
		Collections.sort(ems);//对分数进行排序
		BigDecimal topmark = null,lowestmark = null,total = new BigDecimal(0);
		int rank = ems.size();
		for(int i = 0;i<ems.size();i++){
			ExamMark em = ems.get(i);
			if(i==0)lowestmark = em.getMark();//最低分
			if(i==ems.size()-1)topmark = em.getMark();//最高分
			em.setExamtime(exam.getExamtime());
			em.setRank(rank--);
			total = total.add(em.getMark());
		} 
		exam.setAverage(total.divide(new BigDecimal(ems.size()),2, BigDecimal.ROUND_DOWN));
		exam.setTopmark(topmark);
		exam.setLowestmark(lowestmark);
		return exam;
	}