Java - Write code to Parse string to Float with default value

Requirements

Write code to Parse string to Float with default value

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String source = "book2s.com";
        float def = 42.45678f;
        System.out.println(ParseFloat(source, def));
    }/*w  ww .ja  va2s  .com*/

    public static float ParseFloat(String source, float def) {
        try {
            return Float.parseFloat(source);
        } catch (NumberFormatException e) {
            return def;
        }
    }
}