You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
Thanks for using decimal4j and for your enhancement request.
It is correct that decimal4j numbers do not currently support scientific notation in string representations. This is kind of by design because it is "fixed precision" and therefore the string representation is always fixed, too.
I do however acknowledge that it would be a good feature and we may add it in the future. For the time being I suppose you'd have to go the way via BigDecimal or Double.parse (the latter of course may involve precision issues and is therefore not optimal).
Hi there,
Right now, it doesn't seem like the
valueOf()
methods on thedecimal4j
classes are able to parse strings that are the scientific notation representation of numbers. For example, if I want to create aDecimal4f
instance of the string representation of the number0.0003
, I'll try something like this:I'll get a
NumberFormatException
error on that last line with the message ofCannot 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 usedecimal4j
classes to parse strings, we have to first feed the string into aBigDecimal
and then feed that into thedecimal4j
class.Thanks!
The text was updated successfully, but these errors were encountered: