i need to convert the following statement to
x = 123456.789;
and print the floating point variable x with 3 digits before the decimal point and two digits after the decimal point.
output
456.78
What i have tried printf("%6.2f",x);
i need to convert the following statement to
x = 123456.789;
and print the floating point variable x with 3 digits before the decimal point and two digits after the decimal point.
output
456.78
What i have tried printf("%6.2f",x);
floating point variable x with 3 digits before the decimal point and two digits after the decimal point.
What you need is floating-point modulo remainder function fmod
double x = 123456.789;
double y = fmod( x, 1000 );
printf("%06.2f",y);
Remember to #include <math.h>
, and compile with -lm
for the math library, example:
gcc test.c -o test -lm