Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Excuse me, how to convert float of C# into int?
Excuse me, how to convert float of C# into int?
The accuracy of int-to-float conversion will be reduced. If you need more precision, you should consider using double type.

If the conversion accuracy changes from int(System. Int32) floating will reduce, the following code:

Static void Main(string[] args)

{

Int32 number = Int32. MaxValue

Console. WriteLine (number);

Console. WriteLine ((floating point) number);

Console. ReadLine();

}

The output is:

2 147483647

2. 147484E+09

Extended data:

When performing forced type conversion between int (assuming int is 32 bits), float and double formats, the principles are as follows:

From int to float, the number will not overflow, but it may be rounded.

Converting from int and float to double can preserve accurate values. Because double has a larger range and higher precision (significant digits).

From double to float, because the range of float is smaller, the value may overflow to +∞ or -∞. In addition, because the precision of float is small, it may be rounded.

Convert from float and double to int and the value will be rounded to zero. For example, 1.999 will be converted to 1, and-1.999 will be converted to-1. At the same time, the value may overflow.

Baidu encyclopedia -c#