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

Format double

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
0
0
US
is there a way to format a double?
for example
Can I format 95.8586321465
as
98.96
 
If you're using printf, you can do:
Code:
printf("%2.2f",dblDouble) ;
and this will *guarantee* you two digit IN FRONT of the decimal and two digits BEHIND. This prints to standard output.

For using something like cout<<, you can set the parameters by using the &quot;ios::setf()&quot; function. Link:


Later,


Peter

--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
char dblstr [50];
double y = 48538509731.957587020283475983;

strcpy (dblstr, FloatToStr (y).c_str ());
for (unsigned int x = 0; x < strlen (dblstr); x++)
{
if (dblstr [x] == '.')
{
x = x + 3;
dblstr [x] = NULL;
}
}

Edit1->Text = dblstr;

It could use some help for the proper rounding of the last
digit.

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top