How can I convert BigInteger
value to BigDecimal
without using new
operator?
For instance, if I have an integer value like:
abc=4000.
I should get the output as:
xyz= 4000.0
How can I convert BigInteger
value to BigDecimal
without using new
operator?
For instance, if I have an integer value like:
abc=4000.
I should get the output as:
xyz= 4000.0
use valueOf
if you mean that your own code should not use new
operator.
BigDecimal.valueOf(abc.longValue());
if abc
is a BigInteger
.
If you want to create the object without using new
in your code and in the code of the jre then you can not do it. BigDecimal.valueOf()
uses new to create a BigDecimal object.
No you cant, you can do it only with primitive types, everyting else is an object and has to be instantiate by using new
operator. It might use it "under the hood" in example wrapped in factory method like valueOf
for BigDecimals
but it will be still using it.