469,943 Members | 2,712 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

displaying ints in price form

Hello all,

I want to display a list of ints for example 100, 1000, 10000 as prices
$1.00, $10.00, $100.00.

Can I do this?

I guess I have to use the iomanip lib. But the only manipulators I know
deal with floats.

Thanks, I'll keep trying.
Jul 23 '05 #1
4 1345
Oh, I have an idea, should I convert the ints into floats for display
purposes?

Is that the only way?

"mchoya" <mi******@sbcglobal.net> wrote in message
news:0p****************@newssvr17.news.prodigy.com ...
Hello all,

I want to display a list of ints for example 100, 1000, 10000 as prices
$1.00, $10.00, $100.00.

Can I do this?

I guess I have to use the iomanip lib. But the only manipulators I know
deal with floats.

Thanks, I'll keep trying.

Jul 23 '05 #2
"mchoya" <mi******@sbcglobal.net> wrote in message
news:QC****************@newssvr17.news.prodigy.com ...
Oh, I have an idea, should I convert the ints into floats for display purposes?
I would not unless you truly wish to represent
fractional quanties of money not restricted to
multiples of some unit such as the cent.
Is that the only way?
For any problem, there are usually many
solutions. This is one of the usual cases.
"mchoya" <mi******@sbcglobal.net> wrote in message news:0p****************@newssvr17.news.prodigy.com ...
Hello all,

I want to display a list of ints for example 100, 1000, 10000 as prices $1.00, $10.00, $100.00.

Can I do this?
I would suppose so. A computer can certainly
be made to do it.
I guess I have to use the iomanip lib. But the only manipulators I know deal with floats.


You might find it easier to just use integer division
and the modulo operator to break your quantities
into dollar and cent components, then print them
out with whatever other punctuation you like.

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 23 '05 #3
Thanks, I tried that. It does not display the last zero in for example 100
to $1.00.
"Larry Brasfield" <do***********************@hotmail.com> wrote in message
news:aI****************@news.uswest.net...
"mchoya" <mi******@sbcglobal.net> wrote in message
news:QC****************@newssvr17.news.prodigy.com ...
Oh, I have an idea, should I convert the ints into floats for display
purposes?


I would not unless you truly wish to represent
fractional quanties of money not restricted to
multiples of some unit such as the cent.
Is that the only way?


For any problem, there are usually many
solutions. This is one of the usual cases.
"mchoya" <mi******@sbcglobal.net> wrote in message
news:0p****************@newssvr17.news.prodigy.com ...
Hello all,

I want to display a list of ints for example 100, 1000, 10000 as prices
$1.00, $10.00, $100.00.

Can I do this?
I would suppose so. A computer can certainly
be made to do it.
I guess I have to use the iomanip lib. But the only manipulators I know
deal with floats.


You might find it easier to just use integer division
and the modulo operator to break your quantities
into dollar and cent components, then print them
out with whatever other punctuation you like.

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.

Jul 23 '05 #4
"mchoya" <mi******@sbcglobal.net> wrote in message
news:YT****************@newssvr17.news.prodigy.com ...
Thanks, I tried that. It does not display the last zero in for example 100 to $1.00.

#include <iostream>
#include <sstream>

int main(int an, char *ap[])
{
while (an-- > 1) {
std::istringstream iss(ap++[1]);
unsigned ds = 0;
iss >> ds;
unsigned dollars = ds/100;
unsigned cents = ds%100;
std::cout << '$' << dollars << '.';
std::cout.fill('0');
std::cout.width(2);
std::cout << cents << std::endl;
}
}
"Larry Brasfield" <do***********************@hotmail.com> wrote in message news:aI****************@news.uswest.net...
"mchoya" <mi******@sbcglobal.net> wrote in message
news:QC****************@newssvr17.news.prodigy.com ...
Oh, I have an idea, should I convert the ints into floats for display purposes?


I would not unless you truly wish to represent
fractional quanties of money not restricted to
multiples of some unit such as the cent.
Is that the only way?


For any problem, there are usually many
solutions. This is one of the usual cases.
"mchoya" <mi******@sbcglobal.net> wrote in message news:0p****************@newssvr17.news.prodigy.com ...
Hello all,

I want to display a list of ints for example 100, 1000, 10000 as prices $1.00, $10.00, $100.00.

Can I do this?


I would suppose so. A computer can certainly
be made to do it.
I guess I have to use the iomanip lib. But the only manipulators I know deal with floats.


You might find it easier to just use integer division
and the modulo operator to break your quantities
into dollar and cent components, then print them
out with whatever other punctuation you like.


--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.>
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Steven | last post: by
10 posts views Thread by Ed | last post: by
3 posts views Thread by Gigi.com | last post: by
1 post views Thread by .Net Sports | last post: by
3 posts views Thread by M.-A. Lemburg | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.