DecimalFormat exercise..., decimalformat exercise
Package test; import java. text. decimalFormat; class FormatDemo {public void format1 (String pattern, double value) {// This method is used to format and display a number. DecimalFormat df = null; // declare the DecimalFormat Class Object df = new DecimalFormat (pattern); // instantiate the object and input the template String str = df. format (value); // format the number System. out. println ("use" + pattern + "format number" + value + ":" + str) ;}}; public class NumberFormatDemo02 {public static void main (String args []) {FormatDemo demo = new FormatDemo (); // demo of the formatting object class. format1 ("###,###. ### ", 111222.34567); demo. format1 ("000,000.000", 11222.34567); demo. format1 ("###,###. ### ¥ ", 111222.34567); demo. format1 ("000,000.000 $", 11222.34567); demo. format1 ("##. ### % ", 0.345678); demo. format1 ("00. ### % ", 0.0345678); demo. format1 ("###. ###\ u2030 ", 0.345678) ;};/** use ###,###. ### format a number 111222.34567: 111,222.346 use 000,000.000 format a number 11222.34567: 011,222.346 use ###,###. ### $ format the number 111222.34567: 111,222.346 $ format the number 000,000.000: 11222.34567 $ format the number 011,222.346: $ use ##. ### % format the number 0.345678: 34.568% 00. ###% format the number 0.0345678: 03.457% ###. ### format the number 0.345678: 345.678 ‰**/