---
title: "四舍五入"
author: "bask"
date: "2009-10-20T15:27:19Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2009-12-08T19:36:48Z"
id: 496594
url: "https://bask.iteye.com/blog/496594"
---

```java

	 /**
	 * 返回整数 积分
	 * @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);
	}
```