Re: money comparison
Posted by
Matt Fair on
Sep 06, 2011; 5:26pm
URL: http://quantlib.414.s1.nabble.com/money-comparison-tp11964p11969.html
I guess the real question is do you want to be able to track fractions of the currency (i.e. cents)? If the currency goes to 2 decimal places, do you want to track to 6 or larger places? Does that make sense in any situation?
Should you floor (i.e. round down) anything past the decimal place of the currency? If you want to do that, then you could store everything in an integer. So for example $102.38 would be stored as 10238. That would eliminate any rounding issues and you could do a straight == of the value to do the comparison.
I don't think you ever want to round up, always down. What are other people's thoughts on this?
Matt
On Tue, Sep 6, 2011 at 5:01 AM, Luigi Ballabio
<[hidden email]> wrote:
On Mon, 2011-09-05 at 09:31 -0600, Matt Fair wrote:
> Luigi,
> I understand that you can call close_enough manually if you need to,
> but from an object oriented standpoint it doesn't make sense. Is
> there a reason why you have both?
It was to have the same behavior as doubles, but I see your point.
That's an implementation detail, not the behavior expected in the domain
(actually, Money shouldn't use a floating-point number at all---we
should store an integer number of cents---but that's for another time.)
I wonder if one should go all the way and compare after rounding?
Thoughts?
Luigi
--
Better to have an approximate answer to the right question than a
precise answer to the wrong question.
-- John Tukey as quoted by John Chambers
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev