473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Double to Currency Output

I'm a total C++ newbie here--my background is largely in Visual Basic. I'm
looking for someone who knows (or can send me in the right direction) on a
method to convert a double to currency for output; moreover, I'm interested
in finding a method that supports the thousandths separator. I have found a
money class that works just fine; however, it doesn't include the
thousandths separator. Any assistance would be greatly appreciated.

Thanks,

Todd
Jul 22 '05 #1
6 12331

"Todd Shillam" <tshillam(@)hotmail.com> wrote in message
news:W6********************@comcast.com...
I'm a total C++ newbie here--my background is largely in Visual Basic. I'm
looking for someone who knows (or can send me in the right direction) on a
method to convert a double to currency for output; moreover, I'm interested in finding a method that supports the thousandths separator. I have found a money class that works just fine; however, it doesn't include the
thousandths separator. Any assistance would be greatly appreciated.


The 'moneyput' facet implements a thousands separator.
See standard header <locale>

-Mike
Jul 22 '05 #2
For C++, research std::iostream's formatting options.

The easier (but not type safe) C option is:
printf, or sprintf

The printf family will let you format strings in many different ways.

But you're going to have to roll your own. Standard C++ doesn't
support a "currency" data type. You'll need to write a function to
output exactly as you want. (Keep the modulus operator in mind!) You
can also create your own Currency class that overloads the output
operators. Study classes and operator overloading.

Otherwise, just a get a C++ book, and study outputting. What you want
isn't difficult, but we (more than likely) won't write it for you.
Plus, we like making VB programmers squirm! ;-) (j/k)
Chris J. (aka Sethalicious)

Jul 22 '05 #3
> The 'moneyput' facet implements a thousands separator.
See standard header <locale>

Cool, I didn't know that! All these years I've been writing my own...

Jul 22 '05 #4

"Sethalicious" <se**********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
The 'moneyput' facet implements a thousands separator.
See standard header <locale>

Cool, I didn't know that! All these years I've been writing my own...


http://www.josuttis.com/libbook
http://www.langer.camelot.de/iostreams.html

-Mike
Jul 23 '05 #5
Mike,

Thanks for the direction; however, I could use an example of how to call a
function in order to display a double in currency format. I was tinkering
with the local class, but I couldn't get it quite right.

Thanks,

Todd

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:7s*****************@newsread3.news.pas.earthl ink.net...

"Todd Shillam" <tshillam(@)hotmail.com> wrote in message
news:W6********************@comcast.com...
I'm a total C++ newbie here--my background is largely in Visual Basic.
I'm
looking for someone who knows (or can send me in the right direction) on
a
method to convert a double to currency for output; moreover, I'm

interested
in finding a method that supports the thousandths separator. I have found

a
money class that works just fine; however, it doesn't include the
thousandths separator. Any assistance would be greatly appreciated.


The 'moneyput' facet implements a thousands separator.
See standard header <locale>

-Mike

Jul 23 '05 #6
"Todd Shillam" <tshillam(@)hotmail.com> wrote in message
news:Dp********************@comcast.com...
Mike,

Thanks for the direction; however, I could use an example of how to call a
function in order to display a double in currency format. I was tinkering
with the local class, but I couldn't get it quite right.


You're welcome to post your code and point out where
you're having trouble. Even if I personally can't
help, I suspect someone here can (and hopefully will).

The function you'd call would be operator<<, but with
the stream imbued with a locale containing the 'money_put'
facet (written by you) which does the formatting you need.
That's what these 'facets' are for, allowing one to customize
output, but still do the output with the simple 'stream << object'
syntax.

When I get a chance, I'll try to throw together an example.
I'll probably need to do some refresher reading first, as
I haven't looked at or worked with this stuff for a while.
Writing this stuff does require doing some imo 'nonintuitive'
things.
I also suggest you get a copy of one or both of the books
whose web links I cited in my reply to "Sethalicious".

The second book gives more in-depth treatment to locales
and facets than does the first.

BTW please don't top-post here. Thank you.

-Mike
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John L | last post by:
Well, another basic type of question...amazing how much I've forgotten - never was a VB guru, but. I can see I'll have to pick up a couple VB5 instruction books - any suggestions on a couple good...
1
by: Brandon McCombs | last post by:
hello, I have an app that pops up a custom dialog box and one of the fields for user input is an account balance field. The data gets put into an Object and eventually into an instance of...
11
by: John | last post by:
Hi, I encountered a strange problem while debugging C code for a Windows-based application in LabWindows CVI V5.5, which led me to write the test code below. I tried this code with a different...
0
by: R. John Reed | last post by:
Hi All, I'm am looking to convert a currency string (e.g. "$1,234.56" to a double value). It appears this will work: double val = Convert.ToDouble(Double.Parse­("$123,456.78901",...
1
by: invinfo | last post by:
keywords: mysql accounting currency decimal fixed "floating point" Quoting the manual: DECIMAL)] If D is omitted, the default is 0. If M is omitted, the default is 10. All basic calculations...
8
by: abdul_n_khan | last post by:
Hello, I have a basic question related to datatypes. I am trying to read a value using Microsoft's ADO recordset from a field (lets call it 'Price') with datatype decimal(19,6) => 19 = Precision,...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
6
by: Alexander Stoyakin | last post by:
Hello, please advise on the following issue. I need to check that difference between two double values is not higher than defined limit. int main() { double limit = 0.3; double val1 = 0.5,...
0
by: =?ISO-8859-1?Q?Marcel_M=FCller?= | last post by:
clintonb wrote: There is nothing like an original double amount. If you care about rounding errors you must not store any currency value in an approximate number. You must not do this even once....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.