Java BigDecimal to toLong(BigDecimal value)

Here you can find the source of toLong(BigDecimal value)

Description

Returns the Long represented by the given value, or null if not an long value.

License

Open Source License

Declaration

private static Object toLong(BigDecimal value) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    /**//from   w ww.  ja va 2 s .  c o m
     * Returns the Long represented by the given value, or null if not an long value.
     */
    private static Object toLong(BigDecimal value) {
        Object number;

        try {
            number = value.scale() == 0 ? Long.valueOf(value.longValueExact()) : null;
        } catch (Exception e) {
            number = null;
        }

        return number;
    }
}

Related

  1. toDouble(BigDecimal b, boolean allownull)
  2. toDouble(BigDecimal bigDecimal)
  3. toDouble(final BigDecimal b)
  4. toDouble(final BigDecimal b)
  5. toInteger(BigDecimal b)
  6. toLongObject(@Nullable final BigDecimal value)
  7. toNumber(final BigDecimal bigDecimal, final Class clazz)
  8. toObject(BigDecimal value)
  9. toPercent(final BigDecimal decimalValue, final MathContext mathCntext)