2 Replies Latest reply: Apr 12, 2011 2:49 AM by YoungWinston RSS

    ISSUE CONVERTING STRING TO BIGDECIMAL  IN JAVA 1.5

    853791
      Our customer is migrated from Java 1.4 to Java 1.5 and they are facing below issue.

      When we are converting string to BigDecimal, in JAVA 1.5 it is post fixing with extra “0”(zero) if the string value ends with single “ ”0” (zero).

      This conversion is working as expected in Java 1.4.

      To overcome this we can use toPlainString() method in Java 1.5. But it is not feasible to make this change all over places in our code.

      Is there any fix available?

      Appreciate your inputs on this.

      thanks
      Guru
        • 1. Re: ISSUE CONVERTING STRING TO BIGDECIMAL  IN JAVA 1.5
          EJP
          There is no bug so no fix. Post some code and we'll tell you what's wrong with it.

          NB I moved this here from the Generics forum where you erroneously posted it for some reason.
          • 2. Re: ISSUE CONVERTING STRING TO BIGDECIMAL  IN JAVA 1.5
            YoungWinston
            user712747 wrote:
            When we are converting string to BigDecimal, in JAVA 1.5 it is post fixing with extra “0”(zero) if the string value ends with single “ ”0” (zero).
            That sounds very odd.
            To overcome this we can use toPlainString() method in Java 1.5. But it is not feasible to make this change all over places in our code.
            Aha! This sounds like conversion from BigDecimal to String; not what you described above. And I have to admit, that change mystified me too, because it goes against the grain of backwards-compatibility. It's possible that it was meant to "standardize" output for floating-point values though.
            Is there any fix available?
            Well, one thing might be to use toPlainString() in the places where you're having problems. The string produced by toString() is still suitable for converting back to BigIntegers (and will do so precisely; I believe the toPlainString() style could produce a BigDecimal with the same value but different scale), so unless you actually need the string for viewing you can leave it alone.

            But as EJP says, post some code.

            Winston