Java BigDecimal to BigInteger

In this post, we will see how to convert BigDecimal to BigInteger in java.

Using BigDecimal constructor

You can simply use BigDecimal's toBigInteger() method to convert BigDecimal to BigInteger.

Please note that this method will simply remove fractional part and you will loss precision while converting from BigDecimal to BigInteger in java.

Here is the complete example to convert BigDecimal to BigInteger in java.

import java.math.BigDecimal;
import java.math.BigInteger;
 
public class BigDecimalToBigIntegerMain {
public static void main(String[] args) {
	    BigDecimal bd= new BigDecimal("10.9");
        BigInteger bi=bd.toBigInteger();
        System.out.println("BigInteger bi: "+bi.toString());
    }
}

When you run above program, you will get below output:

BigDecimal bd: 10

That’s all about how to convert BigInteger to BigDecimal in java.

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.