nick said:
printf("%lf",3.25);
the result is 3.25000
i want the answer correct to 3 decimal places
What should i do?
Short answer: open an elementary C textbook.
Spoon-fed longer answer:
#include <stdio.h>
void show(double x)
{
/* note that the specifier is %f or %g, not %lf or %lg */
printf("total precision of 3 decimal places:\n %.3g\n", x);
printf("3 decimal places to right of decimal:\n %.3f\n\n", x);
}
int main(void)
{
show(3.25);
show(325);
show(.325);
show(3.2574);
show(3.2547);
return 0;
}
total precision of 3 decimal places:
3.25
3 decimal places to right of decimal:
3.250
total precision of 3 decimal places:
325
3 decimal places to right of decimal:
325.000
total precision of 3 decimal places:
0.325
3 decimal places to right of decimal:
0.325
total precision of 3 decimal places:
3.26
3 decimal places to right of decimal:
3.257
total precision of 3 decimal places:
3.25
3 decimal places to right of decimal:
3.255