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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format a double

Status
Not open for further replies.

tougo

Technical User
Sep 9, 2002
27
GB
how can i force a string when converting it to double not to lose it's initial format? (the sting source is a textbox)
what do i mean by that. i have a value +3456,9800 and by converting it to double i get a 3456,98
is there a way to keep the following zeros as well as the plus sign? the need of this, to me, is that i want the same length of characters in each value for a saving in a specific format
 
use the [tt]sprintf()[/tt] function on a string - you can format it any way you like.
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Option 2 using new standards:

#include<iostream>
using std::cout;
using std::endl;
using std::ios;

#include<iomanip>
using std::setiosflags;
using std::resetiosflags;

int main()
{
double d = atof( &quot;86.8400&quot; );

cout << setiosflags( ios::showpoint ) << d << endl;
cout << resetiosflags( ios::showpoint ) << d << endl;

return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top