DecimalFormat exercise..., decimalformat exercise

Source: Internet
Author: User

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 ‰**/


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.