자바 연평균 성 장 률 계산

1549 단어 연평균 성장 률
import java.awt.Desktop;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;
import java.net.URISyntaxException;

/**
 *       
 * 
 * @author MrChu
 * @version 1.0
 * @date 2014 12 31 
 */
public class GrowthRatePerAnnumUtils {

	public static void main(String[] args) {
		try {
			URI uri = new URI(
					"http://baike.baidu.com/link?url=HP48P6GifUY49AJlN3OOjNZjlU1JiG9nm6iZbMbbZ06YJGTnBN7DqGmESKLsZc0jua6rke1tU0yckI2J-bcEm_");
			Desktop.getDesktop().browse(uri);
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		double x = 1762.5 / 991.04;
		double n = 1.0 / 3.0;
		System.out.println(getGrowthRatePerAnnumWithPercent(x, n));
	}
	
	/**
	 *        
	 * @param x
	 * @param n
	 * @return
	 * 		     
	 */
	public static double getGrowthRatePerAnnum(double x, double n) {
		return Math.pow(x, n) - 1;
	}
	
	/**
	 *        
	 * @param x
	 * @param n
	 * @return
	 * 		     ,        
	 */
	public static BigDecimal getGrowthRatePerAnnumWithRounding(double x, double n) {
		BigDecimal bd = new BigDecimal((Math.pow(x, n) - 1) * 100);
		return bd.setScale(2, RoundingMode.HALF_UP);
	}
	
	/**
	 *        
	 * @param x
	 * @param n
	 * @return
	 * 		     ,        ,        
	 */
	public static String getGrowthRatePerAnnumWithPercent(double x, double n) {
		BigDecimal bd = new BigDecimal((Math.pow(x, n) - 1) * 100);
		return bd.setScale(2, RoundingMode.HALF_UP) + "%";
	}

}

좋은 웹페이지 즐겨찾기