Looking back, Java restudying (iv): floating-point type of Java basic data type

Source: Internet
Author: User

Java, as a strongly typed language, means that each variable will have a specific type, there are 8 basic types of Java, there are 4 types of integers (byte, short, int, long), two floating-point types (float, double), 1 character types (char) and a Boolean (Boolean), it is worth noting that although string strings are very common, it is not a basic type.

Second , floating-point type (next integral type)

  Floating-point types represent numbers with decimal parts, and Java includes float and double two floating-point data, float is called a single-precision floating-point number, and double is called double-precision floating-point. According to the float class source can be learned that the maximum value of float is 0x1.fffffep+127f (3.4028235e+38f), The minimum value is 0x0.000002p-126f (1.4e-45f), the length is 4 bytes, and the double precision is twice times of float and the maximum value is 0x1.fffffffffffffp+1023 (1.7976931348623157e+308) With a minimum value of 0x0.0000000000001p-1022 (4.9e-324) and a length of 8 bytes.

Since the effective number of floats is only 6~7 bit, can not meet the needs of daily development work, so in the development process most of the use of double type data, and the type of float data need to add F or F after the value, For example, 2.13F and 3.14f, while floating-point types are double by default, such as 2.13 and 3.14, and of course can be followed by D or D. In hexadecimal notation, the notation for floating-point types is 0x1.****p*, presumably because E is a numeric representation in hexadecimal, so replace it with P.

It is also worth noting that floating-point data does not apply to financial calculations that prohibit rounding errors, mainly because floating-point values are represented by binary systems, so it is not possible to accurately represent fractions, and it is recommended to use the BigDecimal type without error.

Read the source found a more interesting place:

IsNaN (), this method seems to be useless Ah, API description parameter is a non-numeric time to return true, but if the parameter is non-numeric, the compilation error will be reported.

Static public boolean IsNaN (double v) {    return (v! = v);}

  

Looking back, Java restudying (iv): floating-point type of Java basic data type

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.