What can I do to display the correct output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

25th Jan 2020, 6:15 AM
Kaiza Ilomo
Kaiza Ilomo - avatar
3 Answers
+ 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; }
25th Jan 2020, 6:37 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
25th Jan 2020, 6:22 AM
Fermi
Fermi - avatar
0
Thanks for your response
25th Jan 2020, 6:24 AM
Kaiza Ilomo
Kaiza Ilomo - avatar