delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/06/23:44:46

From: "Kirk Hartstrom" <gods_character AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: setprecision() c++
Date: Tue, 7 Mar 2000 08:26:21 -0800
Lines: 20
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-03-33.dial.qnet.com
Message-ID: <38c484bb.0@news.qnet.com>
X-Trace: 7 Mar 2000 04:25:31 GMT, 56k-socal-03-33.dial.qnet.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie 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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019