Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert BigInteger to BigDecimal?

Is there any way to convert a BigInteger into a BigDecimal?

I know you can go from a BigDecimal to a BigInteger, but I can't find a method to go the other way around in Java.

like image 214
Regis Avatar asked Jun 25 '10 03:06

Regis


People also ask

How do I convert BigDecimal to BigInteger?

toBigInteger() converts this BigDecimal to a BigInteger. This conversion is analogous to the narrowing primitive conversion from double to long. Any fractional part of this BigDecimal will be discarded. This conversion can lose information about the precision of the BigDecimal value.

What is the difference between BigDecimal and BigInteger in Java?

The main difference between the BigInteger and BigDecimal is that BigInteger supports arbitrary-precision integers and BigDecimal is for arbitrary-precision fixed-point numbers.

Can BigInteger hold decimal values?

BigInteger is for integers (that is numbers without decimal point) You are trying to use it for working with floating numbers.


1 Answers

You have a parameterized constructor for that.

BigDecimal(BigInteger val)

like image 76
bdhar Avatar answered Sep 21 '22 10:09

bdhar