C - printing a floating number, not precise?
I'm creating a floating variable with the number 123.56789. Then I
directly print that var, but it isn't returning the correct value. How
come? Did I do something wrong? After a look here on the questions, it
seems that I'm not the only one, but the main difference with me and
others is that I directly print the value in the variable and don't do any
operations with it.
#include <stdio.h>
#include <stdlib.h>
int main(void){
float num = 123.56789;
printf("Number is %f", num);
// I expect to print '123.56789'
// But it prints '123.567889' with an extra '8'
//Why?
}
No comments:
Post a Comment