Write code to Parse Float from string and catch exception
//package com.book2s; public class Main { public static void main(String[] argv) { String value = "book2s.com"; System.out.println(getFloat(value)); }//from w ww . j av a 2 s. co m public static float getFloat(String value, float defaultValue) { float result = defaultValue; try { result = Float.parseFloat(value); } catch (Exception ex) { } return result; } public static float getFloat(String value) { return getFloat(value, 0.0F); } }