printf("%.2f",..);
I want to control the number 2 in the example above, put a variable instead of the the number 2.
so if
int var=5;
the argument of printf will be "%.5f".
Is it possible? Thanks.
This should work for you:
A little example program to test it:
#include <stdio.h>
int main() {
float f = 4.3234;
int x = 2;
printf("%.*f", x, f);
return 0;
}
For more information see: http://www.cplusplus.com/reference/cstdio/printf/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With