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.


Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book
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

%d bloggers like this: