Skip to content

DecimalFormat throws NumberFormatException: Infinity on large BigDecimal (works on JVM) #359

@rpiaggio

Description

@rpiaggio

Scala: 2.13.8
Scala.js: 1.9.0

The following code:

  import java.text.DecimalFormat
  val x         = BigDecimal("2e333")
  val formatter = new DecimalFormat("0.0E0")
  println(formatter.format(x.bigDecimal))

Results in:

  • JVM (Temurin 17.0.1+12):
    • 2.0E333
  • JS (Chrome 99.0.4844.51):
demo-fastopt.js:31786 Uncaught java.lang.NumberFormatException: Infinity or NaN: Infinity
    at $c_Ljava_math_BigDecimal$.eval [as valueOf__D__Ljava_math_BigDecimal] (webpack://ScalaJSBundlerLibrary/./demo-fastopt.js?:31786:11)
    at $c_Ljava_text_DecimalFormat.eval [as format__D__jl_StringBuffer__Ljava_text_FieldPosition__jl_StringBuffer] (webpack://ScalaJSBundlerLibrary/./demo-fastopt.js?:54152:166)
    at $c_Ljava_text_DecimalFormat.eval [as format__O__jl_StringBuffer__Ljava_text_FieldPosition__jl_StringBuffer] (webpack://ScalaJSBundlerLibrary/./demo-fastopt.js?:42331:17)
    at $c_Ljava_text_DecimalFormat.eval [as format__O__T] (webpack://ScalaJSBundlerLibrary/./demo-fastopt.js?:32389:15)
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions