Java BigDecimal from toBigDecimal(String value)

Here you can find the source of toBigDecimal(String value)

Description

to Big Decimal

License

Open Source License

Declaration

public static BigDecimal toBigDecimal(String value) 

Method Source Code

//package com.java2s;
/**/* w ww .j  a va  2  s .c  om*/
 *  
 * 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
 * 
 */

import java.math.BigDecimal;

public class Main {
    public static BigDecimal toBigDecimal(String value) {
        return toBigDecimal(value, new BigDecimal("0.0"));
    }

    public static BigDecimal toBigDecimal(String value, BigDecimal defaultValue) {
        if (isNullOrEmpty(value))
            return defaultValue;
        try {
            return new BigDecimal(value.trim());
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

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

Related

  1. toBigDecimal(String s, int scale)
  2. toBigDecimal(String str)
  3. toBigDecimal(String value)
  4. toBigDecimal(String value)
  5. toBigDecimal(String value)
  6. toBigDecimal(T value)
  7. toBigDecimal(Vector doubleVector)
  8. toBigDecimalArray(int[] ints)
  9. toBigDecimalList(double... list)