Java – How to create BigDecimal from long datatype value ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

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);

    }
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: