"Java" Java processing result exception for double addition

Source: Internet
Author: User

    • Mode One (rounding): two decimal places reserved
1 Double   F   =   111231.5585;   2 BigDecimal   b   =   new   BigDecimal (f);   3 Double   F1   =   B.setscale (2,   bigdecimal.round_half_up). Doublevalue ();  
    • Way two:
1 java.text.DecimalFormat   df   =new   java.text.DecimalFormat ("#.00");   2 Df.format (the number you want to format);
      • Cases:
        1 New Java.text.DecimalFormat ("#.00"). Format (3.1415926)

        #.00 represents two decimal places #.0000 four decimal places and so on ...

    • Way three:
1 double d = 3.1415926; 2 String result = string. Format ("%.2f");
      • %.2f%. Indicates that any number of digits before the decimal point 2 indicates that the result of the two-bit decimal format is F for floating-point
    • Detailed reference: http://www.jb51.net/article/46010.htm

"Java" Java processing result exception for double addition

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.