I want to set custom precision using printf()
like for example:
double pi = 3.14159265358979323846;
cin>>n;
cout<<setprecision(n)<<pi;
I want to implement this same functionality using printf()
I want to set custom precision using printf()
like for example:
double pi = 3.14159265358979323846;
cin>>n;
cout<<setprecision(n)<<pi;
I want to implement this same functionality using printf()
From printf
:
(optional)
.
followed by integer number or*
, or neither that specifies precision of the conversion. In the case when*
is used, the precision is specified by an additional argument of typeint
, which appears before the argument to be converted, but after the argument supplying minimum field width if one is supplied.
So:
int n = ...;
printf("%.*f\n", n, pi);