Java tutorial
//package com.java2s; //License from project: Apache License public class Main { /** * Convert float value wraped in string to float safely. */ public static float toFloatSafely(String text) { float result = -1.0f; text = text.trim(); try { result = Float.parseFloat(text); } catch (NumberFormatException e) { e.printStackTrace(); } return result; } }