4 Replies Latest reply: May 23, 2013 12:28 PM by morgalr RSS

    Java

    771342
      Hi,

      I am deleting 2 numbers but o/pt is getting rounded and i dont want it be rounded.

      Math.pow (10, 14) - Math.pow(10, -6) = 1 000 000 000 000 00

      But i want the o/p 999 999 999 999 99.99 99 99

      Can anyone help?

      Edited by: gogiB on May 23, 2013 7:46 AM

      Edited by: gogiB on May 23, 2013 8:02 AM
        • 1. Re: Concurrency
          PhHein
          Read this: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
          • 2. Re: Concurrency
            gimbal2
            Why did the thread title change to concurrency?

            EDIT:

            oh and now its "java", even less helpful.

            PhHein wrote:
            Read this: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
            Do you have a cliff notes version? My brain hurts :(
            • 3. Re: Concurrency
              abillconsl
              It's interesting. I have a calculator that uses BigDecimal. When I use it to multiply ( (10^9) - (10^-6) ) ... it does the right thing. But when I raise the first to the power of 10 instead of 9, then it does not. In both cases 10^-6 produces .000001, but in the subtraction with the later it breaks down. I didn't complete my code review yet to see why, but with BigDecimal.subtract I know that is the MathContext is ommitted - which it is in my case - the scale is determined by the larger "scale" of the two numbers.

              The OP did not mention how the calculation was performed, so I don't know if this information is of any value or not.

              Edited by: abillconsl on May 23, 2013 11:55 AM
              • 4. Re: Java
                morgalr
                format the output as desired for display.