How can I print a float number, using a fixed precision?
In C would be:
printf("%.20f",number);
Thanks in advance!![]()
This is a discussion on Printing float numbers within the C++ Programming forums, part of the General Programming Boards category; How can I print a float number, using a fixed precision? In C would be: printf("%.20f",number); Thanks in advance!...
How can I print a float number, using a fixed precision?
In C would be:
printf("%.20f",number);
Thanks in advance!![]()
Nothing more to tell about me...
Happy day =)
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
I used to be an adventurer like you... then I took an arrow to the knee.
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
Nothing more to tell about me...
Happy day =)
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...
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT