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