From: "Kirk Hartstrom" Newsgroups: comp.os.msdos.djgpp References: <38c484bb DOT 0 AT news DOT qnet DOT com> Subject: Re: setprecision() c++ Date: Thu, 9 Mar 2000 01:38:10 -0800 Lines: 51 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: 56k-socal-02-44.dial.qnet.com Message-ID: <38c6c815.0@news.qnet.com> X-Trace: 8 Mar 2000 21:37:25 GMT, 56k-socal-02-44.dial.qnet.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com this code worked for me cout.setf(ios::fixed); cout << setprecision(2) << myFloatNumber << endl; I guess it was that cout.setf(ios::fixed) setting that changes setprecision() from significant digits to decimal places, alliteratively I also tried #include main() .... printf("My number %.2f ", myFloatNumber); this bit of c code worked also in my c++ program so now I know two ways to do it. Thanks for the Help. Kirk > try adding these lines before you set the precision > > cout.setf(ios::fixed,ios::floatfield); > cout.setf(ios::showpoint); > > cout< wrote in message news:38c484bb DOT 0 AT news DOT qnet DOT com... > Hi there! I've been programming about a week in c++ and was wondering if > any of you could answer a question for me. > > I want to display a dollar amount (#.##) with two numbers after the decimal > point. My book says I can use something like > cout << setprecision(2) << number_to_display << endl; > > but setprecision() works on significant digits, so 23 with setprecision(2) > shows only 23, and 1 shows as 1.0. > > I have a number to display 0.096875 (the tax for something) and when I use > setprecision(1) I get "0.1" so I set it to 2, and get "0.097" ! I can't get > it to two digits. If there is a better way please tell me. Maybe there is > a different function I should use. I'm pretty sure my stuff is uptodate > because I downloaded it just last week. > > Thanks again for your help. > Kirk > >