Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Sorting numeric strings Date: Fri, 4 May 2012 20:01:50 +0000 (UTC) Organization: UK Free Software Network Lines: 28 Message-ID: References: <2012043021273098748-no@waycom> <0km0q7lrv910pkbfb1lidbdfr3bkfjglui@4ax.com> <3s93q719q1787gb4ihi4fugvn8cvgc8nu2@4ax.com> <29053378.63.1336093904131.JavaMail.geo-discussion-forums@pbctc10> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1336161710 24714 84.45.235.129 (4 May 2012 20:01:50 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Fri, 4 May 2012 20:01:50 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: csiph.com comp.lang.java.programmer:14267 On Thu, 03 May 2012 18:11:44 -0700, Lew wrote: > But then there's BigDecimal, with perfect accuracy. So there are > choices. > Yes. Using floating point for exact financial figures is almost invariably a wrong move. Use int or long, depending on the size of the values you must handle, to represent the value in the smallest subunits, i.e. store dollars, and euros as an integer representing cents, and use an external representation with a decimal point interpolated at the appropriate position[*] for the currency or, alternatively, use BigDecimal. Always used fixed point arithmetic. [*] different currencies have different subunits: I've seen currencies with zero, 2 or 3 digits after the decimal point. I think you'll find that using floating point for financial amounts was an abberation introduced by programmers on early 8 and 16 bit micros who wrote financial packages in BASIC. Early mainframes stored currency values as binary or BCD integers and all modern systems should do the same -- martin@ | Martin Gregorie gregorie. | Essex, UK org |