I have a data type of double, I want to printf the double in the following form:
- If double x=2orx=2.0print2to the screen, which means if I get an integer I print an integer.
- If double x=2.3orx=2.30or any other non-whole number I print2.3to the screen.
Is there any way to do it shortly? or do I need to use if statements or something like that?
double x = 2;
printf("%d", x);
double x = 2.3;
printf("%.1f", x);
This is an illustration only.
I want to printf an integer or a double based on the value I get.
 
     
     
    