+ 4

How to remove zeroes after decimal point in C language.

The out put is "5.000000", whereas it should be just "5".

3rd Nov 2020, 2:54 PM
KishanBGajera
KishanBGajera - avatar
12 Answers
+ 4
Another solution using format specifier: printf("%.0f" , f );
4th Nov 2020, 3:40 AM
Kevin ★
+ 2
printf("%d", (int)5.000000); Edited: add casting to int
3rd Nov 2020, 3:10 PM
Jayakrishna 🇼🇳
+ 2
Oh. Yes. Mirielle I thought it would work .. I had to check it out before.. I did it after posting.. Thank you .. This works well also : float f = 5.0000; int i= f; // int i = (int) f; printf("%d", i) ;
3rd Nov 2020, 3:14 PM
Jayakrishna 🇼🇳
+ 2
Kevin ★ okay Thanks 😄
4th Nov 2020, 3:49 AM
KishanBGajera
KishanBGajera - avatar
+ 2
Store the value in a integer variable or those cast the whole expression to integer.
5th Nov 2020, 7:41 AM
Amit Roy
Amit Roy - avatar
+ 1
Mirielle I guess I've tried it but didn't work for my situation (solving challenge)
3rd Nov 2020, 3:04 PM
KishanBGajera
KishanBGajera - avatar
+ 1
Mirielle sorry dude but didn't get it 😐
3rd Nov 2020, 3:05 PM
KishanBGajera
KishanBGajera - avatar
+ 1
Mirielle okayđŸ€Ł
3rd Nov 2020, 3:08 PM
KishanBGajera
KishanBGajera - avatar
+ 1
float example = 5.5555; int a; a = example; // a = 5
5th Nov 2020, 12:54 PM
Aditya
Aditya - avatar