JDK-6298816 : The return value of BigDecimal.toString method is different when run against 1.4 vs 1.5
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-07-19
  • Updated: 2010-04-26
  • Resolved: 2005-07-19
Related Reports
Relates :  
Relates :  
Description
J2SE Version (please include all output from java -version flag):
  C:\java\j2sdk1.5.0_beta2\bin>java -version
   java version "1.5.0-beta2"
   Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
   Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

Does this problem occur on J2SE 1.4 or 1.4.1 or 1.4.2?  Yes / No (pick one)
   NO

Operating System Configuration Information (be specific):
  OS Name Microsoft Windows XP Professional
  Version 5.1.2600 Service Pack 1 Build 2600

Bug Description:
  Behavior of BigDecimal.toString has changed.  In J2SE 1.4.x and prior, the
  BigDecimal.toString method returned the string representation of the value
  1E-15 as 0.000000000000001.  In J2SE 1.5 the toString method returns the
  value 1E-15 as 1.0E-15.

  While I understand this was done intentionally, this does cause a problem
  in our product which makes J2SE 1.5 not backward compatible with our product.

  It is easy enough to fix in our product, but I felt we should at least point
  out the issue.

Steps to Reproduce (be specific):

BigDecimal      bd = new  BigDecimal("1E-15");
String  val = bd.toString();

                bd = new  BigDecimal(".000000000000001");
                val = bd.toString();

The value returned by both two string methods will be different when run against 1.4 vs 1.5

###@###.### 2005-07-19 18:03:55 GMT

Comments
EVALUATION The JSR 13 expert group was aware of the possible compatability issues when changing the definition of toString; however, changing its definition was deemed necessary to reap the other benefits of the JSR. If the results of toString, old or new, is given to the BigDecimal string constructor, old or new, the results are as compatible as possble. However, other consumers of decimal strings, e.g. database, may not recognize the new format. Therefore, the toPlainString method was added to BigDecimal to provide the original toString behavior. Closing as will not fix. ###@###.### 2005-07-19 18:28:23 GMT
19-07-2005