Declaration, conversion, and calculation of float and double data types

Source: Internet
Author: User

When declaring, a number of parts of float must be added f/f, while Double does not

The declaration of float will add F if it has a decimal part, otherwise it won't be private. Converts a double type to a float type.            float f1 = 1;//ok            float F2 = 1.1f;//Be sure to f            float f3 = 1.23F;            Double declaration does not need to add D            double d1 = 1;            Double D2 = 1.2;            Double d3 = 1.232434377777777;

  

The precision of double is higher than float,double to float for the display conversion, float to double is implicit conversion, and float can only show 6 for the decimal point, the rest is rounded f1 = (float) d3;//1.232435

  

           Console.WriteLine (5/8);//0 int/int=int decimal place is omitted            Console.WriteLine (5.0/8.0);//0.625 double/double=double            Console.WriteLine (5.0/8);//0.625 double/int=double            Console.WriteLine (5f/8f);//0.625 float/float=float            Console.WriteLine (5d/8d);//0.625 double/double=double            Console.WriteLine (1/3*3);//0            Console.WriteLine (1* 3/3);//1            Console.WriteLine (1.0/3*3);//1

  

Declaration, conversion, and calculation of float and double data types

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.