Here you can find the source of toFloat(String value, float defaultValue)
Parameter | Description |
---|---|
value | string value |
defaultValue | default value |
static public float toFloat(String value, float defaultValue)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww.java 2 s . c om*/ * convert the string to an float, and return the default value if * the string is null or does not contain a valid int value * * @param value string value * @param defaultValue default value * * @return float */ static public float toFloat(String value, float defaultValue) { if (value != null) { try { return Float.parseFloat(value); } catch (NumberFormatException n) { } } return defaultValue; } /** * convert the string to an float, and return 0 if * the string is null or does not contain a valid int value * * @param value string value * * @return float */ static public float toFloat(String value) { if (value != null) { try { return Float.parseFloat(value); } catch (NumberFormatException n) { } } return 0; } }