Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basic_stringstream rounds large numbers?!

Status
Not open for further replies.

MattWoberts

Programmer
Oct 12, 2001
156
0
0
GB
Hi,

I'm a bit of a newbie in VC C++, any help would be great:

I am using a basic_stringstream to generate a SQL statement to execute on a database, and into this stream I input a double, like this:

sBuffer << dValue;

This is OK, but if dValue is a larger number than 1000000, then the number is rounded off, e.g. 1000001 becomes 1000000, and 1000007 becomes 1000010. Please help!!
 
I'm not sure that decimal match is an issue here (unless I've missed something) - if I have a string buffer, and use << to add something to the string (in this case the something refers to a double), then why should the string contain other than the value?

On closer inspection it appears that number > 1000000 are being represented exponentially, e.g. 10000049 actually appends to the string buffer as 1.00001e+7, hence the last 2 numbers are rounded and chopped off.

Am I missing something obvious?
 
Force the stringstream to never use floating point using the manipulator classes:
Code:
#include <iomanip>
sBuffer << setw(15) << setiosflags(iso_base::fixed) << dValue;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top