Value Type -- Float Type

Source: Internet
Author: User


1. Float Type Definition

The float keyword indicates a simple type for storing 32-bit floating point values, as shown in Table 4-5.

Table 4-5 Float Type

Type

Fan Wei

Big and small

Type

Float

± 1. 5 × 10-45 to ± 3. 4 × 1038

7-digit

System. Single

2. Float Type identifier

By default, the real number on the right of the value assignment operator is treated as double. Therefore, use the suffix f or F to initialize floating point variables, as shown below:

Float x = 3.5f;

Note:

If no suffix is used in the preceding statement, a compilation error occurs because you try to store a double value in the float variable.

3. Float Type Conversion

Both integer and floating point types can be used in an expression. In this case, the integer type is converted to the floating point type. Calculate the expression according to the following rules:

If one of the floating point types is double, the calculation result of the expression is double type, and the relational expression or Boolean expression is bool type.

If the expression does not have the double type, the calculation result of the expression is of the float type, and the relational expression or Boolean expression is of the bool type.

A floating-point expression can contain the following values:

Positive and Negative

Positive infinity and negative infinity

Non-numeric value (NAN)

A finite set of non-zero values

Function Description: In the following example, a float result is obtained for mathematical expressions of the int, short, and float types. Note that there is no double in the expression.

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.