C output different

Why is the output different in C?
1
2
3
4
5
6
7
<#include<stdio.h>
#include<conio.h>
void main()
{float a=19234.84797;
 printf("%f",a);
 getch();
}>


Instead of having 19234.84797 as output, the output is 19234.847656 or some other longer number such as 100000.000000 or something else. I really wonder how this is possible. Please help me. Thanks.
Since you didn't specify the precision option for your number, you get the default number of decimal places, if you want fewer you need to add the width and precision specifiers to the printf() specifier.
A float is typically a 32 single precision value with only about 7 digits of accuracy. You're asking for 10 digits which is probably too much. Try using double instead.
http://en.wikipedia.org/wiki/Single-precision_floating-point_format
Topic archived. No new replies allowed.