Here you can find the source of toLong(BigDecimal value)
private static Object toLong(BigDecimal value)
//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; } }