
Initialising BigInteger using double value is not a good way to go about it because double is not a precise representation of the actual number like 44.34. Below is the description of this problem and an appropriate way to avoid it.
If we initialise a BigInteger as follows:-
BigInteger myBigInt = new BigInteger(44.34);
There will be some precision loss i.e. it’s value will be either slightly greater then 44.34 or slightly lesser.
Hence the correct way of initialising BigInteger is as follows:-
BigInteger myPreciseBigInt = new BigInteger(“44.34”);
Passing the expected value as a String ensures absolute precision as we expected.
Tagged in
spstech
Java developer and blogger. Passionate about clean code, JVM internals, and sharing knowledge with the community.
Hey there would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a lot quicker then most. Can you recommend a good web hosting provider at a reasonable price? Cheers, I appreciate it!
Feel free to contact us regarding the same at spstechconsulting@gmail.com