How to convert an object to BigDecimal type in Java?

In Java, you can convert an Object type to a BigDecimal type using the constructor of the BigDecimal class. For example:

Object obj = 10.5;
BigDecimal bigDecimal = new BigDecimal(obj.toString());

This converts an object of type Object to an object of type BigDecimal. Additionally, if the object of type Object is a string that represents a number, it can also be directly converted to a BigDecimal type using the constructor of BigDecimal, for example:

Object obj = "10.5";
BigDecimal bigDecimal = new BigDecimal((String) obj);
bannerAds