The large numeric value of the Java double is not displayed as a scientific notation

Source: Internet
Author: User
Double d = new double ("1234567890.12"); 
System.out.println ("d:=" +d);
Java.text.NumberFormat NF = java.text.NumberFormat.getInstance (); 
Nf.setgroupingused (FALSE);


The results displayed are:

D:=1.23456789012e9

d:=1234567890.12


Look at NumberFormat's help.

First of all, you should know what language you use to output, different languages, said the use of the method is different. I am learning Java to tell you the format of Java output bar

The main use of the class: Java.text.DecimalFormat

1. To instantiate an object, you can use the following two methods:

DecimalFormat df= (DecimalFormat) numberformat.getinstance ();

DecimalFormat df1= (DecimalFormat) decimalformat.getinstance ();

Because DecimalFormat inherits from NumberFormat.

2. To set the number of decimal places

The system default number of decimal places is 3, such as:

DecimalFormat df= (DecimalFormat) numberformat.getinstance ();

System.out.println (Df.format (12.3456789));

Output: 12.346

You can now set the decimal number to two digits by using the following method:

Df.setmaximumfractiondigits (2);

System.out.println (Df.format (12.3456789));

The output is: 12.35 add:

The C # format should be a string. Format this method, specifically see

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.