A digital class
1. About digitally formatted: java.text.DecimalFormat;
2. The number format elements:
# Any number , thousandth decimal point 0 is not padded with zeros
Package com.bjpowernode.java_learning; Import the java.text.DecimalFormat; public class D80_1_ { public static void main (String [] args) { // 1. Create a digital format objects @ Demand: Add thousandth DecimalFormat df = new new DecimalFormat ( "####, ###" ); // start formatting // Number The -> String System.out.println (df.format ( 1234567 )); // demand: Add thousandths , two decimal places DecimalFormat DF1 = new new DecimalFormat ( "###, ### ##." ); System.out.println (df1.format ( 1234567.123 )); // demand: Add thousandth, a 4 decimal places, and not enough to make up zero DecimalFormat DF2 = new new DecimalFormat ( "###, ### 00." ) ; System.out.println (df2.format ( 1234567.123 )); } }
二、java.math.BigDecimal
1. This type of data extremely high accuracy, suitable for financial software.
2. Financial Software type double precision is too low
Package com.bjpowernode.java_learning; Import java.math.BigDecimal; public class D80_2_BigDecimal { public static void main (String [] args) { // create a large data the BigDecimal V1 = new new the BigDecimal (10 ); the BigDecimal V2 = new new the BigDecimal (10 ); // do the adder @ V1 + V2; // error: two reference type can not be adding // must call the method of performing an addition operation the BigDecimal V3 = v1.add (V2); System.out.println (V3); } }
Third, generates a random number
Package com.bjpowernode.java_learning; Import java.util.Random; public class D80_3_Random { public static void main (String [] args) { // create a new random number generator the Random R & lt = new new the Random (); // generated int type of random number // int r.nextInt = I (101); // [random number between 0-100] // System.out.println (I); // loop generates five random numbers for ( int I = 0; I <. 5; I ++ ) { System.out.println (r.nextInt ( 101 )); } } }
Fourth, the source code:
D80_1_DecimalFormat.java
D80_2_BigDecimal.java
D80_3_Random.java
https://github.com/ruigege66/Java/blob/master/D80_1_DecimalFormat.java
https://github.com/ruigege66/Java/blob/master/D80_2_BigDecimal.java
https://github.com/ruigege66/Java/blob/master/D80_3_Random.java
2.CSDN:https://blog.csdn.net/weixin_44630050
3. Park blog: https: //www.cnblogs.com/ruigege0000/
4. Welcomes the focus on micro-channel public number: Fourier transform public personal number, only for learning exchanges, backstage reply "gifts" to get big data learning materials