Convert Double to String
Okay, so I have this code to convert Doubles to Strings.
Code:
string stringify(double x){
ostringstream o;
o << x;
return o.str();
}
My question is two fold. One, assume the double was originally 1.2E+003. I convert it to a string and i'll get something like XXXX.XX, but convert it back to a double via istringstream and I get 1.2E+003. Why?
Two, is there any way to get all the decimal numbers from the double and not round when it converts to string? I'm trying to create a nice round function so that I can convert a number that could have 20+ decimals to 2 decimals. The process would be really simple if i could get it into a string form and then just loop through each number behind the decimal and see if it's higher than 5.
Microsoft Visual Basic 2008 Express Edition
.NET Framwork 3.5 Beta SP1