473,700 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12353

"Todd Shillam" <tshillam(@)hot mail.com> wrote in message
news:W6******** ************@co mcast.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

"Sethalicio us" <se**********@g mail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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******@mkwah ler.net> wrote in message
news:7s******** *********@newsr ead3.news.pas.e arthlink.net...

"Todd Shillam" <tshillam(@)hot mail.com> wrote in message
news:W6******** ************@co mcast.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(@)hot mail.com> wrote in message
news:Dp******** ************@co mcast.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 "Sethalicio us".

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
11115
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 (basic level) learning VB books? Okay - in my database I have a sales total box (textsalestotal) and want to multiply whatever that figure is by .07617 which is Missouri tax - if I just use a click event to multiply, for example $30.34 * .07617...
1
12292
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 DefaultListModel. When I use getText() on the field I pass it to Double.parseDouble to convert it so I can store it as a number and not a string. When I display it (either in the list or in the dialog box) I want it to be displayed using currency...
11
2388
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 compiler and got the same erroneous result on two different PCs (with OS Win98 & Win98SE), so it appears to be a problem with ANSI C. I thought that negative double variables could be compared as easily and *reliably* as integers, but apparently...
0
8416
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", System.Globalization.NumberSty­les.Currency));
1
3688
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 (+, -, *, /) with DECIMAL columns are done with a precision of 64 decimal digits. Re: Floating Point limitations and using IEEE format floating point many numbers cannot be stored exactly in a FP format
8
5454
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, 6 = Scale 1) When I read this field into float datatype. I get a value 1.9000, which is correct. But when I read its value in a double datatype I get 1.8999999761581.
116
35882
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 problems elsewhere in another part of the system where that figure was used for some calculation and some eventual truncation led to the system going haywire. So my question is, given this code: int main() { float f = 59.89F;
6
2915
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, val2 = 0.2; if ( (val1 - val2) limit )
0
287
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. Least of all at something like an original value. If you take account of that the question to do a correct back-conversion is obsolete. Of course, if you make some assumptions about the expected values and the domain of the values a conversion...
0
8714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9203
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9060
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7797
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4650
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2379
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.