469,641 Members | 1,129 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Data types like Money or Price

bb
Hi,

Are there any open source data types ( c++ classes ) for Money and/or
Price that I can inherit and customize for my use instead of writing
from the scratch?

Any help would be much appreciated.

Thanks.

Nov 5 '07 #1
9 4678
bb wrote:
Hi,

Are there any open source data types ( c++ classes ) for Money and/or
Price that I can inherit and customize for my use instead of writing
from the scratch?

Any help would be much appreciated.

Thanks.
Here they are:

class Money
{
};

class Price
{
};
Nov 5 '07 #2
typedef int?

Besides, what do you want those classes to do? I doubt there is
anything you'd find that suits your needs.

Nov 5 '07 #3
typedef int?

Then my 0.02$ will be worth 0...
Nov 6 '07 #4
On Nov 6, 11:02 am, "Gernot Frisch" <M...@Privacy.netwrote:
typedef int?

Then my 0.02$ will be worth 0...
Or 2 ;) Or whatever accuracy.

Nov 6 '07 #5
There was an attempt to submit a fixed-point decimal library to Boost,
but it was not accepted: http://archives.free.net.ph/message/...ab8488.en.html

Maybe you can dig the source somewhere.

Nov 6 '07 #6
On Tue, 06 Nov 2007 18:08:40 +0000, Zeppe wrote:
>bb wrote:
>I have started hand coding all the required operators, bounds checking
etc. specific to my project requirement. ( inheritance heirarchy :
MyDouble <- MyPrice <- MyMoney )

I don;t really want to know why the Money ntherits from the price :)
.... and MyPrice from MyDouble. Isn't the primary purpose of a Money
class to avoid double?
>Check out this if you want
http://quantlib.org/reference/class_...1_1_money.html
Thank you, looks very professional - and it even has a Date class :-)
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Nov 6 '07 #7
On 2007-11-05 04:26:27 -0500, anon <an**@no.nosaid:
bb wrote:
>Hi,

Are there any open source data types ( c++ classes ) for Money and/or
Price that I can inherit and customize for my use instead of writing
from the scratch?

Any help would be much appreciated.

Thanks.

Here they are:

class Money
{
};

class Price
{
};
You didn't declare virtual destructors. Your classes may have troubles
with inheritance. :)

--

-kira

Nov 6 '07 #8
On Nov 6, 5:40 pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
On Nov 6, 9:16 am, bb <muralibal...@gmail.comwrote:
[snip]
I have started hand coding all the required operators,
bounds checking etc. specific to my project requirement. (
inheritance heirarchy : MyDouble <- MyPrice <- MyMoney )
If you've got a careful and complete specification of how
your money class is supposed to behave, you are already
much farther along than the typical application involving
money. Eventually most such projects wind up here asking
how they get the roundoff of pennies correct. It's a lot
of fun telling them that I can't quite read their spec
from where I'm sitting, then having them say they don't
have a spec. Usually they get confused at that point.
At least in the EU, the spec is a given; EU directives say
exactly how you have to round the cents.
Just a suggestion: Consider whether you really need that
inheritance. Consider whether what you really want is a
Currency class. (Or maybe call it Cash or Money or some
such.) Then when you have a price you can make that class
contain a Currency as a data member.
His inheritance doesn't make any sense at all. Generally
speaking, you probably need: a general Decimal class, to handle
the basic arithmetic; a monitary value class (MoneyAmount, or
some such) which has a Decimal in its implementation (but
controls rounding, etc., in a specific way), and a third class
which has both a MoneyAmount and a currency indicator (Euro,
GBP, USD, etc.).

[...]
Without getting too much into your specific app it's hard to
know whether the inheritance is the correct approach.
These are values, so inheritance is almost certainly the wrong
approach.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 7 '07 #9
Kira Yamato wrote:
On 2007-11-05 04:26:27 -0500, anon <an**@no.nosaid:
>bb wrote:
>>Hi,

Are there any open source data types ( c++ classes ) for Money and/or
Price that I can inherit and customize for my use instead of writing
from the scratch?

Any help would be much appreciated.

Thanks.

Here they are:

class Money
{
};

class Price
{
};

You didn't declare virtual destructors. Your classes may have troubles
with inheritance. :)
Oh damn... They are not tested - thats why ;)
Nov 7 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by D. Shane Fowlkes | last post: by
5 posts views Thread by DC Gringo | last post: by
7 posts views Thread by bartvanhemelen | last post: by
1 post views Thread by Alex | last post: by
7 posts views Thread by erikcw | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.