how to convert percentage String to BigDecimal?

In java, how to convert percentage String to BigDecimal ?

Thanks

String percentage = "10%";
BigDecimal d ; // I want to get 0.1 

Answer

BigDecimal d = new BigDecimal(percentage.trim().replace("%", "")).divide(BigDecimal.valueOf(100));

Leave a Reply

Your email address will not be published. Required fields are marked *