Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Does C language have data rounding? When will rounding be used? Data type conversion?
Does C language have data rounding? When will rounding be used? Data type conversion?
Both float and double data in C language are floating-point numbers, so there is rounding problem in the decimal part. When the specified number of output digits is within the precision range, the system will automatically round it off without manual intervention. If the decimal part is also within the precision range, such as 10.0/2.0 = 5.0, when the number of output digits is more than 2, the following 1 is 0. At this time, of course, rounding is not necessary.

There are two ways to convert data types. One is the default cast. For example, when data of types char, short, Int, Long and float are assigned to variables of type double, the compiler will automatically realize the conversion, because this conversion is inherently lossy when the accuracy is high. The other is to manually force type conversion, such as dnum = (double) inum; That is to say, the plastic variable inum is converted into double-precision data first, and then paid to dnum. When assigning a high-precision type variable to a low-precision type variable, the compiler will prompt you unless you cast it manually.