Java – How to create BigDecimal from long datatype value ?

Problem Statement

You need to create BigDecimal values from long type value in your Java program.

Solution

Use BigDecimal.valueOf method to create BigDecimal from the long value.

import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {

        System.out.println("Abundantcode.com Java Tutorials");
        long lng = 19866;

        BigDecimal input = BigDecimal.valueOf(lng);
        System.out.println("Using BigDecimal.valueOf " + input);

    }
}