Here you can find the source of toBigDecimal(final Number n)
public static BigDecimal toBigDecimal(final Number n)
//package com.java2s; /*//from w w w . j a v a2 s . co m * Copyright (c) 2017, Matthew Lohbihler * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.math.BigDecimal; import java.math.BigInteger; public class Main { public static BigDecimal toBigDecimal(final Number n) { if (n == null || n instanceof BigDecimal) return (BigDecimal) n; if (n instanceof BigInteger) return new BigDecimal((BigInteger) n); return BigDecimal.valueOf(n.doubleValue()); } }