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
Leave a Reply