Java DecimalFormat: javadecimalformat

Source: Internet
Author: User
Tags java decimalformat

Java DecimalFormat: javadecimalformat

DecimalFormat is a subclass of NumberFormat used to format decimal numbers.

Package com. myk. hash; import java. text. decimalFormat; public class App {public static void main (String [] args) {// number format, # And 0 are placeholders ,#: when the number of digits to be formatted is insufficient, # blank space is filled; 0: when the number of digits to be formatted is insufficient, 0 DecimalFormat df1 = new DecimalFormat ("#. # "); // format the number System. out. println (df1.format (0.01); DecimalFormat df2 = new DecimalFormat ("0.000"); // number format System. out. println (df2.format (0.01); // The number is displayed in % format, and the decimal to percentage is automatically converted to DecimalFormat df3 = new DecimalFormat ("# 0.000%"); // number format System. out. println (df3.format (0.11); // The number is displayed in % format. The decimal to percentage is automatically converted to DecimalFormat df4 = new DecimalFormat ("#. ##% "); // format the number System. out. println (df4.format (0.01111); // use "," to separate digits by three digits. DecimalFormat df5 = new DecimalFormat (", ###"); // format the number in System. out. println (df5.format (981725025); DecimalFormat df6 = new DecimalFormat ("top, ###"); // number format System. out. println (df6.format (981725025); DecimalFormat df7 = new DecimalFormat ("###,###. 000 "); // format the number System. out. println (df7.format (981725025.981725025); // -- rounding }}

Result

0.010.01011.000% 1.11% 981,725,025 top 981,725,025 981,725,025.982

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.