ITeye博客

四舍五入

bask · 2009-10-20 15:27 · java基础 · 编程语言 · Markdown


	 /**
	 * 返回整数 积分
	 * @param price 
	 * @param tmp 比率值
	 * @return
	 */
	public static Integer getIntegerFormat(Integer price,Float tmp) {
		Integer returnValue = 0;
		if(price !=null && tmp != null && tmp !=0) {
			NumberFormat numberFormat = new DecimalFormat("#0");
			returnValue = Integer.parseInt(numberFormat.format(price*0.01/tmp));
		}
		return returnValue;
	}
	
	/**
	 * 返回格式化比率
	 * @param price 
	 * @param tmp 积分
	 * @return
	 */
	public static String getStringFormat(Integer price,Integer tmp) {
		return getStringFormat(price,tmp,"#0.0000");
	}
	
	public static String getStringFormat(Integer price,Integer tmp,String pattern) {
		NumberFormat format = new DecimalFormat(pattern);
		return format.format(price*0.01/tmp);
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。