|
-
September 3rd, 2008, 10:18 PM
#16
Re: Double output problem
According to the documentation, setprecision(2) would arrange that. The rest of the padding you'd use setw() for.
-
September 3rd, 2008, 10:56 PM
#17
Re: Double output problem
 Originally Posted by Lindley
According to the documentation, setprecision(2) would arrange that. The rest of the padding you'd use setw() for.
I tried that, no dice. Still shows the E notation. This is really annoying. I guess i just have to go find function to round to significant figures. I could use Ceil or Floor, but I want the decimals. heh.
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 3rd, 2008, 10:58 PM
#18
Re: Double output problem
There's no way it should be using scientific notation if you put the fixed manipulator in there....?
-
September 4th, 2008, 12:17 AM
#19
Re: Double output problem
of course it doesn't with Fixed. However, I want a solution that doesn't add zeros. So i'm at the point i'm hacking together a function for it. Now to figure out why converting it to a string yields xxxx.xx but converting it back to a double via istringstream yields the E notation.
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 4th, 2008, 03:34 AM
#20
Re: Double output problem
Am I right in assuming that you don't want trailing zeros?
123.45
765.2
7868
instead of
123.45
765.20
7868.00
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
September 4th, 2008, 07:11 AM
#21
Re: Double output problem
Code:
cout << "text" << fixed << right << setw(x) << setprecision(0) << value << endl;
Should specify no trailing zeros. Using setprecision(2) will yield standard money notation. The rest of your formatting should be controlled via setw(); *only* the minimum number of decimal places should be controlled via setprecision().
-
September 4th, 2008, 08:07 AM
#22
Re: Double output problem
That's what I thought. However, it doesn't work. It just gets put in scientific notation. Here's a screenshot.
http://i96.photobucket.com/albums/l190/c89c/Capture.jpg
It shows E even with 2 setprecision and setw(7).
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 4th, 2008, 08:14 AM
#23
Re: Double output problem
I suppose it's possible the ordering of the manipulators matters. Try putting "fixed" both to the right and left of setprecision (alternately, not at the same time).....
-
September 4th, 2008, 08:46 AM
#24
Re: Double output problem
Don't know what your doing but...
Code:
#include <iostream>
#include <iomanip>
int main()
{
double d = 1900.0;
std::cout << std::fixed << std::setw(8) << std::setprecision(2) << d << std::endl;
return 0;
}
Gives me '1900.00'
Changing to std::setprecision(0) gives me '1900'
Can you show the line you are actually using rather than having us guess?
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
September 4th, 2008, 10:05 AM
#25
Re: Double output problem
Code:
cout << "\t\tMonthly Payment:\t" << setprecision(2) << setw(7) << pmt << endl;
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 4th, 2008, 10:07 AM
#26
Re: Double output problem
....why is std::fixed missing again? You *do* realize that all those extra zeros you were complaining about were the result of having setprecision(>2) before, don't you?
-
September 4th, 2008, 10:18 AM
#27
Re: Double output problem
Yes, but this particular line never had setprecision greater than 2 and i've checked and it has exactly two decimal places when it's returned. For some reason, it gets retrned and then output does something weird and puts it in scientific notation.
For example:
Before Return: 1875.11
After Return: 1875.11
When I just do
Code:
cout << pmt << endl;
I get 1875.11. However, once it reaches the line setprecision and setw it does scientific notation for some reason.
Edit: I just tried putting fixed in and it fixes the problem. I'm still wondering why setprecision and setw would make such a difference.
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
-
September 4th, 2008, 10:37 AM
#28
Re: Double output problem
http://www.cplusplus.com/reference/i...precision.html
If you don't specify fixed-point, then setprecision specifies the maximum number of meaningful digits to display. If the value is 1875.11, and you say setprecision(2), then it's only going to display 1 and 8----and the best way to do that is to write 1.8e3.
Of you do specify fixed-point, then the meaning of setprecision() changes to be the number of digits after the decimal to display.
-
September 4th, 2008, 10:40 AM
#29
Re: Double output problem
Code:
double pmt = 1875.11;
cout << "\t\tMonthly Payment:\t" << setprecision(2) << setw(7) << pmt << endl;
Gives '1.9e+003'
Code:
double pmt = 1875.11;
cout << "\t\tMonthly Payment:\t" << fixed << setprecision(2) << setw(7) << pmt << endl;
Gives '1875.11'
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
September 4th, 2008, 10:52 AM
#30
Re: Double output problem
 Originally Posted by Lindley
http://www.cplusplus.com/reference/i...precision.html
If you don't specify fixed-point, then setprecision specifies the maximum number of meaningful digits to display. If the value is 1875.11, and you say setprecision(2), then it's only going to display 1 and 8----and the best way to do that is to write 1.8e3.
Of you do specify fixed-point, then the meaning of setprecision() changes to be the number of digits after the decimal to display.
Somehow, that seems like something our professor should have distinguished. He just used it like it determined decimal places and didn't affect the number at all.
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|