5 Replies Latest reply: Apr 25, 2013 2:39 PM by jschellSomeoneStoleMyAlias RSS

    Java 1.6 BigDecimal Issue

    1004966
      Hi

      I am facing an issue using BigDecimal in Java 1.6

      BigDecimal bd = new Bigdecimal ("0.000000000").setScale(9,BigDecimal.ROUND_FLOOR);
      System.out.println (bd);

      I get the exponential output *0E-9* but I need this as a non exponential value i.e; 0.000000000

      I do not want to use bd.toPlainString(); method as I need the BigDecimal object and not a String object. I will have to pass this BigDecimal value to an end system running on Java1.4. Could you please help me sort out this issue ?



      Rgds, Raj.
        • 1. Re: Java 1.6 BigDecimal Issue
          jschellSomeoneStoleMyAlias
          Best I can suppose you are confusing display format for data.

          The two display values you referred to represent the same data.
          If the other system/api takes a BigDecimal then it is up to it to display the value correctly or to use the data correctly. Nothing you do externally will change that.
          • 2. Re: Java 1.6 BigDecimal Issue
            1004966
            I am sending 0E-9 as the tag value in xml to an external system. Do you mean the external system should accept the data without any issues ? (The system assumes it to be a BigDecimal).

            Rgds, Raj.
            • 3. Re: Java 1.6 BigDecimal Issue
              EJP
              What are you passing the BigDecimal to?
              • 4. Re: Java 1.6 BigDecimal Issue
                1004966
                I have to construct an xml whose xsd definition had decimal as the datatype for one of the tag. When I was working on Java1.4, I was able to pass the BigDecimal as is but after switching to Java1.6, the xml validation fails.

                <price>0.000000001</price> --- earlier

                <price>1E-9</price> --- now the xml looks this way



                Rgds, Raj.
                • 5. Re: Java 1.6 BigDecimal Issue
                  jschellSomeoneStoleMyAlias
                  1001963 wrote:
                  I have to construct an xml whose xsd definition had decimal as the datatype for one of the tag. When I was working on Java1.4, I was able to pass the BigDecimal as is but after switching to Java1.6, the xml validation fails.
                  That doesn't answer the question. Please stop telling us that it fails at the external system and start telling us how your code works.

                  One of the following is true.
                  - You are using a XML library and you are passing BigDecimal TO IT
                  - You wrote code that creates XML and you are transforming BigDecimal yourself using BigDecimal.toString() - either explicitly or implicitly.

                  Which one is it?