Java tutorial
//package com.java2s; public class Main { /** * * @param number * @param defaultValue * @return */ public static float convertStringToFloat(String number, float defaultValue) { try { return Float.parseFloat(number); } catch (NumberFormatException e) { return defaultValue; } } /** * * @param number * @return */ public static float convertStringToFloat(String number) { return convertStringToFloat(number, -1f); } }