Java Double Number Create toDouble(String value, double defaultValue)

Here you can find the source of toDouble(String value, double defaultValue)

Description

to Double

License

Open Source License

Declaration

public static double toDouble(String value, double defaultValue) 

Method Source Code

//package com.java2s;
/**//w ww  .j ava  2  s .co  m
 *  
 * Copyright (c) 2015 Fannie Mae, All rights reserved.
 * This program and the accompany materials are made available under
 * the terms of the Fannie Mae Open Source Licensing Project available 
 * at https://github.com/FannieMaeOpenSource/ezPie/wiki/License
 * 
 * ezPIE? is a registered trademark of Fannie Mae
 * 
 */

public class Main {
    public static double toDouble(String value) {
        return toDouble(value, 0.0);
    }

    public static double toDouble(String value, double defaultValue) {
        if (isNullOrEmpty(value))
            return defaultValue;
        try {
            return Double.parseDouble(value.trim());
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    public static boolean isNullOrEmpty(String value) {
        return (value == null) || value.isEmpty();
    }
}

Related

  1. toDouble(String value)
  2. toDouble(String value)
  3. toDouble(String value, double defaultValue)
  4. toDouble(String value, double defaultValue)
  5. toDouble(String value, Double defaultValue)
  6. toDouble(String value, Double fallback)
  7. toDouble(T value)