Java reserved two-bit decimal pits

Source: Internet
Author: User

Directly below the code:

DecimalFormat df1 = new DecimalFormat ("#.00");
DecimalFormat DF2 = new DecimalFormat ("##### #0.00");
Double D1 = 1.0;
Double d2 = 5;
Double d3 = 0.11;
Double d4 = 1.11;
System.out.println ("DF1:" +df1.format (D1) + "PK" +df2.format (D1));
System.out.println ("DF1:" +df1.format (D2) + "PK" +df2.format (D2));
System.out.println ("DF1:" +df1.format (D3) + "PK" +df2.format (D3));
System.out.println ("DF1:" +df1.format (D4) + "PK" +df2.format (D4));

Operation Result:

df1:1.00 PK 1.00
df1:5.00 PK 5.00
df1:.11 PK 0.11
df1:1.11 PK 1.11

When the double value is less than 1 o'clock DF1 will omit 0 before the decimal point, and DF2 will not. It is also the difference between them, the pit to fill.

Java reserved two-bit decimal pits

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.