0
What can I do to display the correct output?
What is wrong with the code when I declare data type as float, initialize a variable with a float number e.g 300.653465 but when I apply the printf function it displays only 300.6535 or it adds unknown digits like 300.653503
3 Antworten
+ 1
Use double in order to get more decimals.
#include <stdio.h>
int main(void) {
double x = 300.653465; //has 6 decimals
printf("value of x: %.6f", x); // "%.6f" will make it show up to 6 decimals
return 0;
}
+ 4
Take a look at why floating point values stored in variables, or in computer systems in general, can be inaccurate.
https://www.sololearn.com/Discuss/1949137/?ref=app
https://www.sololearn.com/Discuss/2018392/?ref=app
https://www.sololearn.com/Discuss/2102703/?ref=app
https://www.sololearn.com/Discuss/1955174/?ref=app
0
Thanks for your response