FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 244   



There are two ways you can convert a String into float in Java

  1. Using Float.parseFloat(String input) - This returns primitive float
    String input = "123.45";
    float output = Float.parseFloat(input);
    System.out.println(output);
    
  2. Using Float.valueOf(String input) - This returns Float type
    String input = "123.45";
    Float output = Float.valueOf(input);
    System.out.println(output);
    
    Note: Code will through NumberFormatException if you do not pass a valid float String. Ex. if you pass "foo" that causes NumberFormatException.



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News