Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java "100%" to number

Is there a built in routine in Java that will convert a percentage to a number for example, if the string contains 100% or 100px or 100, I want a float containing 100.

Using Float.parseInt or Float.valueOf result in an exception. I can write a routine that will parse the string and return the number, but I'm asking does this already exist?

like image 334
SPlatten Avatar asked Nov 30 '22 16:11

SPlatten


1 Answers

I think you can use:

NumberFormat defaultFormat = NumberFormat.getPercentInstance()
Number value = defaultFormat.parse("100%");
like image 58
eg04lt3r Avatar answered Dec 05 '22 11:12

eg04lt3r