Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Turbo C on Windows 7. When I declare a float and such as float f1 = 6.6666666
and try to show it with printf("%0.7f", f1); it shows shows some at random value after four correct digits of precision after decimal. It works fine for double data type. Why is that? Please help! Here is my program:-

#include<stdio.h>

void main(void)
{
float f1=6.6666666;
double d1 = 6.6666666;

printf("%0.7f \t %0.7f", f1,d1);
}

It works fine for double but it shows random value after 4 digits of precision after decimal for float. Please help!
Posted
Updated 9-Oct-14 19:48pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Oct-14 1:54am    
I don't know what would it mean "Turbo C on Windows 7". "Turbo C" I knew targeted DOS. Are you using some DOS emulator, or something?

What does it mean, 10 degree of precision?

—SA
Sergey Alexandrovich Kryukov 10-Oct-14 3:08am    
By the way, please stop posting fake "solution". Only one of you 5 "solution" posts could be considered as an answer.
—SA

1 solution

The C/C++ float type is the IEE 754[^] single precision format which has a precision of 7.22 decimal digits. If you need a higher precison you must use the double type which has a precision of 15.95 digits.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900