How can I print a float number, using a fixed precision?
In C would be:
printf("%.20f",number);
Thanks in advance! :)
Printable View
How can I print a float number, using a fixed precision?
In C would be:
printf("%.20f",number);
Thanks in advance! :)
One way is to use a combination of the setiosflags function and the setprecision function, i.e:
Output is:Code:float f = 9.87463f;
cout << f << endl;
cout << setiosflags(ios::fixed) << setprecision(3) << f << endl;
9.87463
9.875
Thanks for the reply, but I was talking about fill with 0īs the number, for example:
Output:Code:float f=0.6;
float f2=0.12;
printf("%.5f\n%.5f");
0.60000
0.12000
something like this?Code:#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float f = .56;
cout.setf(ios::showpoint | ios::fixed);
cout << f << endl;
return 0;
}
the code that hk_mp5kpdw gave you should do what you want it to...