Boost logo

Boost :

From: Greer, Joe (jgreer_at_[hidden])
Date: 2008-06-09 10:07:55


There is a bit more to it than that, but often a 64bit fixed scaling factor money type is sufficient. Things do need rescaled after multiplications and divisions, so it becomes not so simple that a class isn't warranted to handle the details. However, you don't need an arbitrary precision package for it. I have seen a 64bit integer with a fixed scale of 4 used for money calculations before. It can handle any likely values. Sadly, I don't have any code for this on hand.

joe

-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Mathias Gaunard
Sent: Monday, June 09, 2008 8:31 AM
To: boost_at_[hidden]
Subject: Re: [boost] boost::decimal ?

Mårten Rånge wrote:

> A decimal class would be very useful for ERP and Financial systems as in
> many cases of the typical customers work with the decimal system instead of
> the binary system.

Isn't simply using integers enough?

> 1
> -0.2
> -0.2
> -0.2
> -0.2
> -0.2

1 = 10 / 10
-0.2 = 2 / 10
-0.2 = 2 / 10
-0.2 = 2 / 10
-0.2 = 2 / 10
-0.2 = 2 / 10

= 0 / 10 = 0

and now you have no problem.
Just store an integer and how many times it has been multiplied by 10
compared to the real value.
Then when doing an operation make sure that number is the same for both.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk