first, format date and time
Example:
public void FormatDateTime () {
dateformat format = new SimpleDateFormat ("YYYY year mm month DD Day HH:mm:ss");
Date date = new Date ();
System.out.println (Format.format (date));
}
Results: March 02, 2016 14:13:08 II, formatted numbers
Example:
public static void FormatNumber () {
double d = 34563.88888;
DecimalFormat format = new DecimalFormat ("##.###");
System.out.println (Format.format (d));/will be rounded
format.applypattern ("##.###%");
System.out.println (Format.format (d));
Format.applypattern ("###,###.000");
System.out.println (Format.format (d));
}
Results:
34563.889
34,563,88.,888%
34,563.889 III. Format of general types
Example:
public static void FormatString () {String str=null;
Str=string.format ("hi,%s,%s,%s", "John", "Dick", "Harry");
System.out.println (str);
System.out.printf ("Capital of the letter A is:%c%n", ' a ');
System.out.printf ("3>7 results are:%b%n", 3>7);
System.out.printf ("Half of 100 is:%d%n", 100/2);
System.out.printf ("100 of the 16 number is:%x%n", 100);
System.out.printf ("100 of the 8 numbers are:%o%n", 100);
System.out.printf ("50 yuan book hit 8.5 discount is:%f Yuan%n", 50*0.85);
System.out.printf ("Above the price of 16 of the number is:%a%n", 50*0.85);
System.out.printf ("Above the price index says:%e%n", 50*0.85);
System.out.printf ("The index of the above price and the shorter length of the floating-point results are:%g%n", 50*0.85);
System.out.printf ("The above discount is%d%%%n", 85);
System.out.printf ("The hash code of the letter A is:%h%n", "a"); }
Results:
Hi, John, Dick, Harry
Letter a
3>7 The result is: false
100 of the half is: the 16 number of
100 is:
100 of the 8 number is: 144
50 Yuan's book 8.5 discount is: 42.500000 Yuan 16 of the above price is: 0X1.54P5
above the price index said: 4.250000e+01
The above price index and the length of the floating-point results is shorter: 42.5000
The above discount is 85%
The hash code of the letter A is: a