Rounding in C language is expressed as follows:
inta= 100.453627 .
printf("%. 1f ",a+0.05); //Round to the tenth place.
printf("%.2f ",a+0.005); //Round to the hundredth place.
By analogy, for a 0.5 type decimal number (such as 0.5, 1 1.5, 18.5), that is, the fractional part can be expressed by the negative power of 2, then the computer can "perfectly" store this decimal number. As for the numbers .6, .7, .8, .9 and .4, .3,. 1, .2, etc., although the computer can't "perfectly" store these numbers, the so-called "+0.5 rounding method" can be used in this case.
The so-called rounding method of adding 0.5 is a counting rule used in C language, which forces floating-point numbers to be converted into integers, only the integers will be retained, but not rounded. Therefore, for decimals that retain integers, we only need to perform forced type conversion after +0.5 on their original basis, and we can realize error-free rounding.
Some standards do not exist in C language rounding:
Rounding in C language is in C98 standard, and there is no rounding function in standard C function library. Many rounding functions such as ceil (), floor (), nearbyint () and round () did not appear until the C99 standard.
The Gcc used now is the C99 standard, while the VC under Windows (including VS2008) is the C98 standard, so it is necessary to follow strict formats, including no inlining, no single line comment//,variables to be written in front of the code block, and so on. The biggest drawback is that there is no support for those functions.