Click here to Skip to main content
15,896,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<stdio.h>
#include<conio.h>

void main()
{
    float n;
    printf("Enter a number");
    scanf("%f", &n);
    printf("Number is....: %f", n);
    getch()
}
Posted
Updated 1-Jan-15 23:53pm
v2

Floating pointer numbers are represented as a factor and and exponent to the base two. This means that they are kind of a trade-off between range and precision. Some numbers, as the one you showed, cannot be represented in that format exactly, but only up to a certain numbers of significant digits. In your case that's 6 digits, which is the usual number for C float variables.

See also:
http://en.wikipedia.org/wiki/Floating_point[^]
 
Share this answer
 
Try with double
C++
double n;
printf("Enter a number");
scanf("%lf",&n);
printf("Number is....: %lf",n);

This might solve your problem
 
Share this answer
 
v2
Comments
nv3 2-Jan-15 5:51am    
No, it will not. Using double will just increase the number of digits that are represented correctly. The principal problem, that floating point numbers are stored as approximations, will remain.
[no name] 2-Jan-15 7:54am    
It will help. At least for OP's example :)

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