Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14267
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Sorting numeric strings |
| Date | 2012-05-04 20:01 +0000 |
| Organization | UK Free Software Network |
| Message-ID | <jo1cje$o4a$1@localhost.localdomain> (permalink) |
| References | (3 earlier) <uKednQ89I8TCwD3SnZ2dnUVZ_sCdnZ2d@earthlink.com> <3s93q719q1787gb4ihi4fugvn8cvgc8nu2@4ax.com> <iuUHyzEIFtoPFwwg@invalid.uk.co.demon.merlyn.invalid> <n296q79vcj1hoi8vunmqem2nbe1litv4av@4ax.com> <29053378.63.1336093904131.JavaMail.geo-discussion-forums@pbctc10> |
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 |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Sorting numeric strings Ben <no@way.com> - 2012-04-30 21:27 -0400
Re: Sorting numeric strings Arne Vajhøj <arne@vajhoej.dk> - 2012-04-30 21:39 -0400
Re: Sorting numeric strings Gene Wirchenko <genew@ocis.net> - 2012-05-01 10:30 -0700
Re: Sorting numeric strings Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-05-01 10:53 -0700
Re: Sorting numeric strings Roedy Green <see_website@mindprod.com.invalid> - 2012-05-01 14:50 -0700
Re: Sorting numeric strings Patricia Shanahan <pats@acm.org> - 2012-05-01 15:02 -0700
Re: Sorting numeric strings Roedy Green <see_website@mindprod.com.invalid> - 2012-05-02 14:36 -0700
Re: Sorting numeric strings Gene Wirchenko <genew@ocis.net> - 2012-05-02 19:57 -0700
Re: Sorting numeric strings Dr J R Stockton <reply1218@merlyn.demon.co.uk.not.invalid> - 2012-05-03 19:41 +0100
Re: Sorting numeric strings Roedy Green <see_website@mindprod.com.invalid> - 2012-05-03 17:40 -0700
Re: Sorting numeric strings Lew <lewbloch@gmail.com> - 2012-05-03 18:11 -0700
Re: Sorting numeric strings Martin Gregorie <martin@address-in-sig.invalid> - 2012-05-04 20:01 +0000
Re: Sorting numeric strings Gene Wirchenko <genew@ocis.net> - 2012-05-04 14:19 -0700
Re: Sorting numeric strings Martin Gregorie <martin@address-in-sig.invalid> - 2012-05-04 23:36 +0000
Re: Sorting numeric strings Dr J R Stockton <reply1218@merlyn.demon.co.uk.not.invalid> - 2012-05-06 17:50 +0100
Re: Sorting numeric strings Gene Wirchenko <genew@ocis.net> - 2012-05-07 10:34 -0700
Re: Sorting numeric strings Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-05-07 12:38 -0500
Re: Sorting numeric strings glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-05-07 17:48 +0000
Re: Sorting numeric strings Gene Wirchenko <genew@ocis.net> - 2012-05-07 11:42 -0700
Re: Sorting numeric strings Roedy Green <see_website@mindprod.com.invalid> - 2012-05-01 13:38 -0700
csiph-web