Java BigDecimal to toDouble(final BigDecimal b)

Here you can find the source of toDouble(final BigDecimal b)

Description

Null save convert of a BigDecimal to a double.

License

Open Source License

Parameter

Parameter Description
b the BigDecimal to convert.

Return

the double or 0.0 if b is null.

Declaration

public static double toDouble(final BigDecimal b) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013, 2014, 2015 QPark Consulting  S.a r.l.
 * /*from w  w w. j  av  a  2  s. c o  m*/
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0. 
 * The Eclipse Public License is available at 
 * http://www.eclipse.org/legal/epl-v10.html.
 ******************************************************************************/

import java.math.BigDecimal;

public class Main {
    /**
     * Null save convert of a {@link BigDecimal} to a double.
     *
     * @param b
     *            the {@link BigDecimal} to convert.
     * @return the double or 0.0 if b is <code>null</code>.
     */
    public static double toDouble(final BigDecimal b) {
        if (b != null) {
            return b.doubleValue();
        } else {
            return 0d;
        }
    }
}

Related

  1. decimalToBytes(BigDecimal v, byte[] result, final int offset, int length)
  2. decimalToString(BigDecimal value)
  3. toBeforeDecimalPointString(BigDecimal bigDecimal)
  4. toDouble(BigDecimal b, boolean allownull)
  5. toDouble(BigDecimal bigDecimal)
  6. toDouble(final BigDecimal b)
  7. toInteger(BigDecimal b)
  8. toLong(BigDecimal value)
  9. toLongObject(@Nullable final BigDecimal value)