Learning Notes--java Digital processing class

Source: Internet
Author: User

1. Digital formatting

Use Java.text.DecimalFormat to format numbers, typically using the DecimalFormat class. Such as:

ImportJava.text.DecimalFormat; Public classdecimalformatdemo{Static  Public voidSimpleformat (String pattern,Doublevalue) {DecimalFormat MyFormat=NewDecimalFormat (pattern); String out=Myformat.format (value); System.out.println (Value+ "" +pattern+ "" +Out ); }     Public Static voidMain (string[] args) {Simpleformat ("###,###.###", 123456.789); }}    

Learn to view other methods of the DecimalFormat class for format processing.

2. Digital operations

2.1 Math Class

such as: Math. Mathematical Methods (trigonometric functions, exponential function, rounding, maximum minimum, absolute value)

2.2 Random Number: Math.random () method

2.3 Random Class

Import Java.util.Random is required, and this class is used to generate random numbers of various basic types, such as Nextint (), nextdouble (), and so on.

2.4 Large numeric operations BigInteger, BigDecimal class

Because the maximum value of the base type int is 2 of 31 minus 1, the BigInteger class is introduced if a larger number is to be computed. When used, import Java.math.Biginteger (BigDecimal) is required.

API Document: http://docs.oracle.com/javase/7/docs/api/

  

 

Learning Notes--java Digital processing class

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.