Convert String to BigDecimal in Java

One possible way to convert a String to a BigDecimal type is by using the constructor method of BigDecimal.

String str = "123.45";
BigDecimal decimal = new BigDecimal(str);

In the example above, we are converting the string “123.45” to a decimal variable of the BigDecimal type. The BigDecimal class has several constructor methods that can be chosen accordingly to convert a string to a BigDecimal.

bannerAds