Java – How to create BigDecimal from string value ?


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try 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


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.
%d bloggers like this: