Convert String to BigDecimal in Java

You can use the constructor of the BigDecimal class to convert a String type of string into BigDecimal type of data, for example:

String str = "123.456";
BigDecimal bd = new BigDecimal(str);

This way, the string “123.456” can be converted to data of type BigDecimal. It is important to note that the BigDecimal constructor can also take a parameter of type MathContext, which specifies precision and rounding mode.

bannerAds