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