DecimalFormat's Simple understanding

Source: Internet
Author: User

package com.sohu.tv.m.servlet;import java.text.decimalformat;/** * just for  simple test * *  @author  liweihan *  @time  2016-12-13 10:47 */ Public class test2 {    public static void main (String[]  args)  {        /**          * DecimalFormat  is a specific subclass of  NumberFormat  that is used to format decimal digits.          * DecimalFormat  includes a pattern   and a set of symbols           *  symbol Meaning:          0   A number          #  a number, not including  0          .  placeholder for decimal separator          ,  Placeholder for the grouping delimiter          ;  delimited format.          -  default negative number prefix.          %  multiply  100  and show as percent           ?  multiplied by  1000  and displayed as a binary currency symbol, in lieu of a currency sign, if double write, with              International currency symbol instead. If it appears in a pattern, replace the decimal delimiter with the currency decimal separator            .          X  any other character used in a prefix or suffix to refer to a special character in a prefix or suffix.          */        double  pi = 3.1415927;        //take an integer          system.out.println (New decimalformat ("0"). Format (PI)); //3         //takes a single-bit integer and a two-bit decimal         system.out.println ( New deciMalformat ("0.00"). Format (pi));  //3.14        //takes two-bit integers and three decimal places, The insufficient portion of the integer is filled with 0         system.out.println (New decimalformat ("00.000"). Format (pi));  //03.142        //take all integer parts          system.out.println (New decimalformat ("#"). Format (PI)); //3         //is calculated as a percentage and takes two decimal places          System.out.println (New decimalformat ("#.##%"). Format (PI)); //314.16%         long c = 2999792458l;        // Displays the scientific notation and takes 5 decimal         system.out.println (New decimalformat ("#.### # #E0 "). Format (c));  //2.99979e9        //Displays the scientific notation for two-bit integers and takes four decimal places          sYstem.out.println (New decimalformat ("00.### #E0"). Format (c));//29.9979e8         //each of the three bits is separated by commas         system.out.println (new  DecimalFormat (", # # #"). Format (c));//2,999,792,458        //embed formatting into text        system.out.println (New decimalformat ("size is per second, # # #米. "). Format (c)); The  //size is 2,999,792,458 meters per second.     }}


This article is from the "My Java World" blog, so be sure to keep this source http://hanchaohan.blog.51cto.com/2996417/1882176

DecimalFormat's Simple understanding

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.