For example:
int main()
{
printf("%.1f",76.75);
return 0;
}
Output: 76.8
I have some results Question.
First of all, why not print 76.7?
Second, how does it revolve around this number?
Since 76.75 completely represents 7675/100, it happens to be between 76.7 and 76.8. When applying “round to Nearest-even”, the next number is considered “even”. This may be the reason why your compilation platform chose to generate this decimal representation as the decimal conversion of the floating point number 76.75.
I tried to use printf to print some floating point numbers.
For example:
int main()
{
printf( "%.1f",76.75);
return 0;
}
Output: 76.8
I have some questions about the result.
< p>First of all, why not print 76.7?
Second, how does it revolve around this number?
In addition to the existing answers, please note that many C compilers try to follow IEEE 754 floating point issues. IEEE 754 recommends rounding from the current rounding mode Conversion from binary floating point to decimal. The default rounding mode is “round to nearest and related to even numbers”. Some compilation platforms do not consider the rounding mode, and the conversion from floating point to decimal is always based on the default nearest Even number mode is rounded.
Since 76.75 completely represents 7675/100, it happens to be between 76.7 and 76.8. When “round to nearest-even” is applied, the latter number is considered to be “Even number”. This may be the reason why your compilation platform chose to generate this decimal representation as the decimal conversion of the floating point number 76.75.