From: Arne Vajhøj on 13 Feb 2010 13:40 On 10-02-2010 13:35, Tom Anderson wrote: > On Tue, 9 Feb 2010, Arne Vajh?j wrote: > >> On 09-02-2010 13:12, Tom Anderson wrote: >>> On Mon, 8 Feb 2010, Arne Vajh?j wrote: >>> >>>> On 08-02-2010 02:09, luc peuvrier wrote: >>>>> On 8 f?v, 04:23, Lew<no...(a)lewscanon.com> wrote: >>>>>> Lew wrote: >>>>>>> just between us, after 30 years of programming I have never handled >>>>>>> monetary data: surprise, right? >>>>>> >>>>>>> I am really happy to learn than float is not proper. >>>>>> >>>>>> Think about the reasons why. >>>>> >>>>> Luc: >>>>> float is an approximate numeric datatype, as defined by ANSI >>>>> standards. >>>>> http://stackoverflow.com/questions/285680/representing-monetary-values-in-java: >>>>> >>>>> >>>>> "Martin Fowler recommends the implementation of a dedicated Money >>>>> class to represent currency amounts, and that also implements rules >>>>> for currency conversion." >>>> >>>> That is one option. >>>> >>>> java.math.BigDecimal may be good enough for many cases. >>> >>> Or int/long and establishing a convention that you're working in pence, >>> or thousandths of a dollar, or whatever is suitable. >> >> Yes, but why bother when BigDecimal already handle it. > > Because you can say + to an int. + and - is a bit easier, but *, / and IO becomes harder. Arne
From: Andreas Leitgeb on 14 Feb 2010 17:46 Arne Vajhøj <arne(a)vajhoej.dk> wrote: > On 10-02-2010 13:35, Tom Anderson wrote: >> On Tue, 9 Feb 2010, Arne Vajh?j wrote: >>> Yes, but why bother when BigDecimal already handle it. >> Because you can say + to an int. > + and - is a bit easier, but *, / and IO becomes > harder. Multipliation with a "scalar" value isn't harder, and I haven't yet had a need to multiply currency-values with other currency- values. £·€, €²,£³ ?-) about IO: well, yes, you gotta apply the scaling first.
From: Arne Vajhøj on 14 Feb 2010 20:26
On 14-02-2010 17:46, Andreas Leitgeb wrote: > Arne Vajhøj <arne(a)vajhoej.dk> wrote: >> On 10-02-2010 13:35, Tom Anderson wrote: >>> On Tue, 9 Feb 2010, Arne Vajh?j wrote: >>>> Yes, but why bother when BigDecimal already handle it. >>> Because you can say + to an int. >> + and - is a bit easier, but *, / and IO becomes >> harder. > > Multipliation with a "scalar" value isn't harder, and I haven't > yet had a need to multiply currency-values with other currency- > values. £·€, €²,£³ ?-) That is not very likely. But some may multiply with exchange rates or interest rates. > about IO: well, yes, you gotta apply the scaling first. Yep. Arne |