Java Float Number Create toFloat(String string)

Here you can find the source of toFloat(String string)

Description

to Float

License

MIT License

Declaration

public static float toFloat(String string) 

Method Source Code

//package com.java2s;
/*/*from  w ww  .j  av  a  2s  .  c  om*/
 * oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

public class Main {
    public static float toFloat(String string) {
        if (isEmpty(string)) {
            return 0.0f;
        }

        try {
            return Float.parseFloat(string);
        } catch (NumberFormatException ex) {
            return 0.0f;
        }
    }

    public static boolean isEmpty(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }

        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }
}

Related

  1. toFloat(String str)
  2. toFloat(String str)
  3. toFloat(String str)
  4. toFloat(String str, float defaultValue)
  5. toFloat(String str, float defaultValue)
  6. toFloat(String text)
  7. toFloat(String text)
  8. toFloat(String value)
  9. toFloat(String value)