Initialization with string in scientific format in Java BigInteger? -
i have need work large numbers (something in range 1e100 - 1e200). however, biginteger
class, seems suitable in general, not recognize strings in scientific format during initialization, not support conversion string in format.
bigdecimal d = new bigdecimal("1e10"); //works biginteger i1 = new biginteger("10000000000"); //works biginteger i2 = new biginteger("1e10"); //throws numberformatexception system.out.println(d.toengineeringstring()); //works system.out.println(i1.toengineeringstring()); //method undefined
is there way around? cannot imagine such class designed assumption users must type hundreds of zeros in input.
scientific notation applies biginteger
s in limited scope - i.e. when number in front of e
has many or fewer digits after decimal point value of exponent. in other situations information lost.
java provides way work around letting bigdecimal
parse scientific notation you, , converting value biginteger
using tobiginteger
method:
biginteger i2 = new bigdecimal("1e10").tobiginteger();
conversion scientific notation can done constructing bigdecimal
using constructor takes biginteger
:
system.out.println(new bigdecimal(i2).toengineeringstring());
Comments
Post a Comment