Java. text. DecimalFormat class decimal format,

Source: Internet
Author: User

Java. text. DecimalFormat class decimal format,

The specific code of the java. text. DecimalFormat class in decimal format is for your reference. The specific content is as follows:

Import java. text. decimalFormat; class FormatDemo {public void format1 (String pattern, double value) {// declare a DecimalFormat object DecimalFormat df = new DecimalFormat (pattern); String str = df. format (value); System. out. println ("format with" + pattern + ":" + value + "Get:" + str) ;}} public class Test {public static void main (String args []) {FormatDemo fd = new FormatDemo (); fd. format1 ("###,###. ### ", 111222.34567); // the front side is not enough to add 0, and the backend is not enough to make up 0 fd. format1 ("000,000.000", 11222.34567); fd. format1 ("###,###. ### ¥ ", 111222.34567); fd. format1 ("000,000.000 $", 11222.34567); // The number of fd. format1 ("##. ### % ", 0.345678); // The number of fd. format1 ("00. ### % ", 0.0345678); // Number of thousands of fd. format1 ("###. ###/u2030 ", 0.345678); // exponential form DecimalFormat df1 = new DecimalFormat (); // use applypattern df1.applyPattern (" 0.000E0000 "); System. out. println (df1.format (111222.34567 ));}}

Program running result:

###,###. ### Style formatting: 111222.34567 get: 111,222.346 use 000,000.000 style formatting: 11222.34567 get: 011,222.346 use ###,###. ### $ format: 111222.34567 get: 111,222.346 use 000,000.000 format: 11222.34567 get: 011,222.346 use ##. ### % format: 0.345678 get: 34.568% use 00. ###% style formatting: 0.0345678 get: 03.457% use ###. ### ‰ style formatting: 0.345678 get: 345.678 ‰ 1.20.e0005

DecimalFormat format template

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.