How to do a conversion with 1.0E-7 (Scientific Notation Converter) - SOLVED

Is there a group of numbers bigger than E-6 decimals?

I’d like to make this simple conversion to decimal with a number E-7 Eg: 8.839E-7

    val c = BigDecimal("8.4805E-6")

    val a = BigDecimal("8.839E-7")

The first println are correctly: 0.0000084805

The second was not converted: 8.839E-7

Does anyone can help-me?

1 Like

If you want more control over how a number is formatted as a string, you should take a look at DecimalFormat.

1 Like

But probably there are a solution on kt, my problem is just with precision of BigDecimal conversion

Big decimal has a constructor that lets you set the precision. Otherwise it should use a precision that can represent the number you pass in.

In any case you still should look into DecimalFormat. Otherwise your BigDecimal can be printed in scientific notation even though internally it is still represented correctly.


@Wasabi375 Thank you for your explanation.

Just for add more information, is possible to show numbers converted using .toPlainString() just like this example below.

    val a = "8.124734E-10"
    val n = BigDecimal(a).toPlainString()

The output is: 0.0000000008124734

1 Like