Reputation: 53
Started to learn C and stacked with one question.
At the chapter about the console output describes the conversion specifications and two of them are %f and %F. I tried to figure out what's the difference between them and wrote a simple C script given below:
#include <stdio.h>
int main(void)
{
float num = 123.456;
printf("First float: %f \n", num);
printf("Second float: %F \n", num);
return 0;
}
The output is:
First float: 123.456001
Second float: 123.456001
Upvotes: 4
Views: 151
Reputation: 310950
From the C Standard (7.21.6.1 The fprintf
function)
A
double
argument representing an infinity is converted in one of the styles [-]inf or [-]infinity — which style is implementation-defined. A double argument representing a NaN is converted in one of the styles [-]nan or [-]nan(n-char-sequence) — which style, and the meaning of any n-char-sequence, is implementation-defined. TheF
conversion specifier producesINF
,INFINITY
, orNAN
instead ofinf
,infinity
, ornan
, respectively.
Upvotes: 4