Java Convert int to BigDecimal

Tags: int BigDecimal

In this Java core tutorial we learn how to convert a int value to a java.math.BigDecimal object in Java programming language.

How to convert int to BigDecimal in Java

In Java, with a given int value we can use the BigDecimal.valueOf(long val) static method to instantiate a new BigDecimal object from an int value as the following example Java code.

ConvertIntegerToBigDecimalExample1.java

import java.math.BigDecimal;

public class ConvertIntegerToBigDecimalExample1 {
    public static void main(String... args) {
        int intValue = 700000;

        // Convert int value to BigDecimal object
        BigDecimal bigDecimalValue = BigDecimal.valueOf(intValue);

        System.out.println("Integer value: " + intValue);
        System.out.println("BigDecimal value: " + bigDecimalValue);
    }
}
The output as below.
Integer value: 700000
BigDecimal value: 700000

We can also use the BigDecimal(int val) constructor to create a new instance of BigDecimal from a given int value as the following Java program.

ConvertIntegerToBigDecimalExample2.java

import java.math.BigDecimal;

public class ConvertIntegerToBigDecimalExample2 {
    public static void main(String... args) {
        int intValue = 98765;

        // Convert int value to BigDecimal object
        BigDecimal bigDecimalValue = new BigDecimal(intValue);

        System.out.println("Integer value: " + intValue);
        System.out.println("BigDecimal value: " + bigDecimalValue);
    }
}
The output as below.
Integer value: 98765
BigDecimal value: 98765

Happy Coding 😊

Java Convert long to BigDecimal

Java Convert double to BigDecimal

Java Convert float to BigDecimal

Java Convert BigInteger to BigDecimal

How to use BigDecimal in Java by Examples

How to Add two BigDecimal values in Java

How to Subtract two BigDecimal values in Java

How to Multiply two BigDecimal values in Java

How to Divide two BigDecimal values in Java

Java Convert BigDecimal value into double value

Java Convert BigDecimal value into float value

Java Convert BigDecimal value into int value

Java Convert BigDecimal value into long value

Java Convert BigDecimal value into short value

Java Convert BigDecimal value to byte value

Java Convert BigDecimal to String

Java Convert String to BigDecimal

Java Compare two BigDecimal values

How to Negate BigDecimal Value in Java

How to Round BigDecimal Value in Java

How to Get Absolute of BigDecimal Value in Java

Java Convert BigDecimal to BigInteger