Java - Write code to convert nullable Object To Float

Requirements

Write code to convert nullable Object To Float

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        Object d = "book2s.com";
        System.out.println(nullObjectToFloatEmpty(d));
    }//  ww w  . j  a v  a 2 s. com

    public static float nullObjectToFloatEmpty(Object d) {
        float i = 0;
        if (d != null) {
            String dual = d.toString().trim();
            try {
                i = new Float(dual).floatValue();
            } catch (Exception e) {
                System.out.println("Unable to find integer value");
            }
        }
        return i;
    }
}

Related Exercise