Hi everyone,
I just began to learn c, and here's the first problem I encountered,
the text is about the 3 data types (int, float, char). Here particularly, it talks about precision in floats. Just to test it, I set up a simple code, Here:
Code:
adrian@Adriansys:~/ccode$ cat floating.c
#include <stdio.h>
main()
{
float num1 = 91.273;
printf("\n%.1f\n", num1);
printf("%.2f\n", num1);
printf("%.3f\n", num1);
printf("%.6f\n", num1);
printf("%f\n", num1);
printf("%.14f\n", num1);
}
adrian@Adriansys:~/ccode$ ./floating
91.3
91.27
91.273
91.273003
91.273003
91.27300262451172
adrian@Adriansys:~/ccode$
And the question is, if num1 was made to be equal to 91.273, where are these numbers after .273 coming from? (The 0's are obvious, but the 26245........)
Thanks for all the help,