Scala Programming Language
  1. Scala Programming Language
  2. SI-8116

Inconsistent application of MathContext when creating BigDecimal

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.3, Scala 2.11.0-M7
    • Fix Version/s: Scala 2.11.0-M8
    • Component/s: Misc Library
    • Labels:
      None

      Description

      BigDecimal can't make up its mind whether to round or not when given a java.math.MathContext:

      scala> BigDecimal(123456789, new java.math.MathContext(5))
      res8: scala.math.BigDecimal = 123456789
      
      scala> BigDecimal(123456789L, new java.math.MathContext(5))
      res9: scala.math.BigDecimal = 1.2346E+8
      
      scala> BigDecimal(123456789f, new java.math.MathContext(5))
      res10: scala.math.BigDecimal = 1.2346E+8
      
      scala> BigDecimal(123456789d, new java.math.MathContext(5))
      res11: scala.math.BigDecimal = 1.2346E+8
      
      scala> BigDecimal(new java.math.BigDecimal(123456789d), new java.math.MathContext(5))
      res12: scala.math.BigDecimal = 123456789
      
      scala> BigDecimal.valueOf(123456789d, new java.math.MathContext(5))
      res13: scala.math.BigDecimal = 123456789
      

        Activity

        Show
        Adriaan Moors added a comment - https://github.com/scala/scala/pull/3316

          People

          • Assignee:
            Rex Kerr
            Reporter:
            Rex Kerr
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development