Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.ParseException;

public class Main {
    public static Double diff(Double d1, Double d2) {
        if (d1 == null)
            d1 = Double.valueOf(0);
        if (d2 == null)
            d2 = Double.valueOf(0);
        return d1 - d2;
    }

    public static Double diff(Object o1, Object o2) {
        Double returnVal = Double.valueOf(0);
        if (o1 == null || o2 == null)
            return returnVal;
        Double val1 = Double.valueOf(0);
        Double val2 = Double.valueOf(0);
        if (o1 instanceof Double) {
            val1 = (Double) o1;
        } else {
            val1 = string2double(o1.toString());
        }

        if (o2 instanceof Double) {
            val2 = (Double) o2;
        } else {
            val2 = string2double(o2.toString());
        }

        returnVal = val1 - val2;
        return returnVal;
    }

    public static Double string2double(String str) {
        Double returnVal = Double.valueOf(0);
        try {
            returnVal = Double.valueOf(str);
            java.text.NumberFormat nf = java.text.NumberFormat.getInstance(java.util.Locale.ENGLISH);
            returnVal = Double.valueOf(nf.parse(str).doubleValue());
        } catch (ParseException e) {
        } catch (Exception e) {
        }
        return returnVal;
    }
}