Skip to content

Double.toBigDecimal() loses precision when using scale #330

Description

@alyssoncs

Describe the bug
Converting from Double to BigDecimal while specifying a scale works different compared with String to BigDecimal.

To Reproduce
Steps to reproduce the behavior:

val decimalMode = DecimalMode(
    scale = 2,
    roundingMode = RoundingMode.ROUND_HALF_TO_EVEN,
)
val a = 1234.0.toBigDecimal(decimalMode = decimalMode)
val b = "1234.0".toBigDecimal(decimalMode = decimalMode)
println(a)
println(b)

This prints:

0.0E+4
1.234E+3

Expected behavior
I would expect this to print:

1.234E+3
1.234E+3

Platform
JVM

If JS (please complete the following information):

If Smartphone (please complete the following information):

Additional context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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