Now you know why many real programs use BCD packages and why EBCDIC
eventually is not so funny to non midrange/mainframe types. Your problem
certainly isn't funny to your controller or to you if it is your paycheck.
( Although if you are getting 22452.99 from 33453, you have a bigger problem
than any of us can resolve ;-) ) BTW, this is not a java unique problem;
check out how floats/doubles work in any language ( that follows
standards. )
The base answer is to use the BigDecimal class. True to it's name, it
is big and slow, but should be accurate. You could also use a long or
BigInteger and supply decimals yourself, but this ends up being a
proprietary solution.
In addition, Mike Cowlishaw from IBM Hursley has been working on a
replacement. He sent the below message back in February and the proposal is
now under consideration.
================================================
Some news on decimal arithmetic for Java:
First, I am very pleased to report that it was confirmed to me
yesterday that IBM plans to release the com.ibm.math.BigDecimal
class (and the supporting MathContext class) as a fully supported
integral part of all new IBM Java Developer Kits (JDKs), starting
with JDK 1.1.8, on all platforms as they update their JDKs.
Second, the latest beta version of the code and documentation
(including javadoc format) is now available from:
http://www2.hursley.ibm.com/decimal
A full list of changes is at the back of the .pdf document.
I recommend this document or the HTML pages as the 'place to start'.
Third; IBM is still working with Sun to work this into the Java core
for Java 1.3; a review meeting with them next week may lead to
further changes.
Fourth, the code 'freeze' for this release will likely to be in the
second half of March, so this would be an excellent time to review
the proposal and suggest any changes (preferably minor!).
Mike
================================================
Good Luck.
Joe Sam Shirah
Autumn Software
-----Original Message-----
From: Steffen Detsch <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, June 08, 1999 3:49 AM
Subject: currency values
>Hello,
>
>I'm using float for storage of currency values. Is the float type the
>appropriate choice for this purpose?
>
>Sometimes a value like 33453 will automatically transformed to
>22452.99. How can I prevent Java doing this?
>
>
>Thanx,
>
>Steffen
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html