Number formatting in Java

Source: Internet
Author: User
/* About number formatting: java.text.DecimalFormat; number format elements: #任意数字, thousand-bit. Decimal 0 Not enough 0*/import Java.text.decimalformat;public class Numbertest01{public static void Main (string[] args) {//1. Create a number Format object//requirements: Add thousands of bits. DecimalFormat df = new DecimalFormat ("###,###");//Start Formatting//number-->stringsystem.out.println (Df.format (1234567)); "1,234,567"//Requirements: Add thousand points, retain 2 decimal places decimalformat df1 = new DecimalFormat ("###,###.##"); System.out.println (Df1.format (1234567.123)); "1,234,567.12"//demand: Add thousands of points, retain 4 decimal places, and not enough to fill 0DecimalFormat df2 = new DecimalFormat ("###,###.0000"); System.out.println (Df2.format (1234567.123)); }}


This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1662502

Number formatting in Java

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.