Java – How to create BigDecimal from string value ?


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

Problem Statement

You want to create a BigDecimal value from a string type in Java.

Solution

Use the BigDecimal class and pass the string value in the constructor to create the BigDecimal value as shown below.

import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {

        System.out.println("Abundantcode.com Java Tutorials");
        String str = "198654586.297292792";

        // Creating BigDecimal from string value in Java
        BigDecimal input = new BigDecimal(str);

        System.out.println(input);

    }
}

The output of the above program is

Abundantcode.com Java Tutorials

198654586.297292792

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: