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