Java calculates average annual growth rate

Source: Internet
Author: User
Tags pow

Import Java.awt.desktop;import java.io.ioexception;import java.math.bigdecimal;import java.math.RoundingMode; Import Java.net.uri;import java.net.urisyntaxexception;/** * Average annual growth rate * * @author Mrchu * @version 1.0 * @date December 31, 2014 */public class Growthrateperannumutils {public static void main (string[] args) {try {uri uri = new Uri ("Http://baike.baidu . Com/link?url=hp48p6gifuy49ajln3oojnzjlu1jig9nm6izbmbbz06yjgtnbn7dqgmesklszc0jua6rke1tu0ycki2j-bcem_ ");D Esktop.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)); /** * Get average annual growth rate * @param x * @param n * @return * Average annual growth */public static double Getgrowthrateperannum (double x, double n) {re Turn Math.pow (x, N)-1;} /** * Average annual growth rate * @param x * @param n * @return * Average annual growth rate, retain two digits after the decimal point */public static BigDecimal Getgrowthrateperannumwithroundin g (double x, double n) {BigDecimal BD = New BigDecimal ((Math.pow (x, N)-1); return Bd.setscale (2, roundingmode.half_up);} /** * Get average annual growth rate * @param x * @param n * @return * Average annual growth rate, two digits after the decimal point, and a percent sign for */public static String GETGROWTHRATEPERANNUMWITHPE Rcent (double x, double n) {BigDecimal BD = new BigDecimal ((Math.pow (x, N)-1); return Bd.setscale (2, RoundingMode.H ALF_UP) + "%";}}

Java calculates average annual growth rate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.