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?
I think you can use:
NumberFormat defaultFormat = NumberFormat.getPercentInstance()
Number value = defaultFormat.parse("100%");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With