Data types and Conversions

Source: Internet
Author: User

Data type: Built-in, reference;

Eight basic types: 6+1+1:6, 1-character, 1-type Boolean

1>byte 8-bit 1-byte, -128~127,

2>int 32-bit 4-byte, minimum value is-2,147,483,648 ( -2^31), maximum value is 2,147,483,647 (2^31-1)

3>long 64-bit 8-byte, minimum value is-9,223,372,036,854,775,808 ( -2^63), maximum value is 9,223,372,036,854,775,807 (2^63-1)

4>float single precision, 32-bit

5>double Double Precision 64 bit

6>short 16 bit, minimum value is-32768 ( -2^15), maximum value is 32767 (2^15-1)

The 7>char 16-bit (Unicode encoding) minimum value is \u0000 (that is, 0); The maximum value is \uffff (that is, 65,535);

Conclusion:

1. Data type conversion to a floating-point type can have a loss of precision

2.byte short int long float double can be converted directly to each other (strong turn)

public class Testdouble {public    static void Main (String args[]) {        System.out.println ("0.05 + 0.01 =" + (0.05 + 0 .));        System.out.println ("1.0-0.42 =" + (1.0-0.42));        SYSTEM.OUT.PRINTLN ("4.015 * =" + (4.015 *));        System.out.println ("123.3/100 =" + (123.3/100));}    }

The result is:

Reason:

When the value of the double type is added and reduced, Numeric values are converted to binary values such as 10001.10010110011 This means that the expression is added and reduced, but in the conversion to binary code representation, the number of bits stored in the fractional part will not be enough, that is, infinite loop decimal, which is the main cause of the micro-gap.

Data types and Conversions

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.