HcgRandon HcgRandon - 1 year ago 104
Java Question

Convert string to float?

Just as title says. I don't believe it is possible to do this but if it is let me know.

This is needed for a bukkit (minecraft server) plugin I'm writing. I want to take a command: tnt [power]. Where power is the string returned that I want to convert to float.


Answer Source

Use Float.valueOf(String) to do the conversion.

The difference between valueOf() and and parseFloat() is only the return. Use the former if you want a Float (object) and the latter if you want the float number.