Java Rounding Methods

Source: Internet
Author: User

/** <Br/> * returns the number of digits after the specified decimal point to the parameter. <br/> * @ Param sourcedata indicates the metadata to be acquired. <br/> * @ Param Str optional format (mainly used "#. 0 "format, which is the first digit after the decimal point ;"#. 00 "indicates the second decimal point, and so on) <br/> * @ return the rounded data <br/> */<br/> Public static double getdouble (double sourcedata, string SF) <br/>{< br/> decimalformat df = new decimalformat (SF); <br/> string STR = DF. format (sourcedata); <br/> return double. parsedouble (STR ); <br/>}</P> <p>/** <br/> * returns the rounding of the digit after the specified decimal point to the parameter <br/> * @ Param sourcedata <br/> * @ Param a The number of digits after the decimal point (for example: 10: one digit after the decimal point; 100: the second digit after the small data, and so on) <br/> * @ return the rounded data <br/> */<br/> Public static float getfloatround (double sourcedata, int) <br/> {<br/> int I = (INT) math. round (sourcedata * A); // place a after the decimal point, move forward and rounding <br/> float F2 = (float) (I/(float) ); // restore the digit after the decimal point <br/> return F2; <br/>}

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.