Skip to content

Parsing strings with scientific notation #14

Description

@samskeller

Hi there,

Right now, it doesn't seem like the valueOf() methods on the decimal4j classes are able to parse strings that are the scientific notation representation of numbers. For example, if I want to create a Decimal4f instance of the string representation of the number 0.0003, I'll try something like this:

double myNumber = 0.0003;
String myNumberString = String.valueOf(myNumber);
System.out.println(myNumberString); // prints "3.0E-4"
Decimal4f myNumberDecimal = new Decimal4f.valueOf(myNumberString)

I'll get a NumberFormatException error on that last line with the message of Cannot parse Decimal value with scale 4 for input string: "3.0E-4".

It'd be great to have the library accommodate scientific notation strings -- this is something BigDecimal does, so if we want to use decimal4j classes to parse strings, we have to first feed the string into a BigDecimal and then feed that into the decimal4j class.

Thanks!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions