The DecimalFormat tool class provided by Java formats the data
Doublepi=3.1415927;//Pi//take a single-digit integerSystem.out.println (Newdecimalformat ("0"). Format (PI));//3//take an integer and a two decimal placeSystem.out.println (Newdecimalformat ("0.00"). Format (PI));//3.14//take two-bit integers and three decimal places, and 0 fill in the less-than-integer parts. System.out.println (NewDecimalFormat ("00.000"). Format (PI));//03.142
//take all integer partsSystem.out.println (Newdecimalformat ("#"). Format (PI));//3//count as a percentage and take two decimal placesSystem.out.println (NewDecimalFormat ("#.##%"). Format (PI));//314.16% Longc=299792458;//Speed of Light//Display as scientific notation, and take five decimal placesSystem.out.println (Newdecimalformat ("#.#### #E0"). Format (C));//2.99792E8//scientific notation shown as a two-bit integer, with four decimal placesSystem.out.println (Newdecimalformat ("00.### #E0"). Format (C));//29.9792E7//each three bits is delimited by commas. System.out.println (Newdecimalformat (", # # #"). Format (C));//299,792,458//embed formatting into textSystem.out.println (Newdecimalformat ("The speed of light is the size of every second, # # #米. "). Format (C));
from:http://blog.csdn.net/wangchangshuai0010/article/details/8577982
Java Foundation--decimalformat