Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert percentage String to BigDecimal?

Tags:

java

In java, how to convert percentage String to BigDecimal ?

Thanks

String percentage = "10%";
BigDecimal d ; // I want to get 0.1 
like image 444
user595234 Avatar asked Mar 15 '12 02:03

user595234


People also ask

Can we convert String to BigDecimal?

We can convert a String into BigDecimal in Java using one of the below methods: BigDecimal(String) constructor. BigDecimal. valueOf() method.

How do I convert a String to a percent?

It would be something like Double. valueOf(your_string) or Decimal. valueOf(your_string). If it is stored as whole number, you could convert it then divide by 100 to do math on it.

How do you change a percent to a decimal in Java?

double decimalNumber = theVolume / 100.0; The . 0 at the end converts it to a decimal number.

How do you change a percent to a decimal in Python?

Summary. To convert a percentage string to a decimal number use the built in function float with the replace string methods like so: float("30.0%". replace("%", ""))/100 .


1 Answers

Try new DecimalFormat("0.0#%").parse(percentage)

like image 79
namalfernandolk Avatar answered Sep 21 '22 20:09

namalfernandolk