Java BigDecimal from toBigDecimal(final Number n)

Here you can find the source of toBigDecimal(final Number n)

Description

to Big Decimal

License

Mozilla Public License

Declaration

public static BigDecimal toBigDecimal(final Number n) 

Method Source Code


//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());
    }
}

Related

  1. toBigDecimal(Double d)
  2. toBigDecimal(double val)
  3. toBigDecimal(double[][] a)
  4. toBigDecimal(final byte value)
  5. toBigDecimal(final Double d)
  6. toBigDecimal(final Number number)
  7. toBigDecimal(final Number number)
  8. toBigDecimal(final Number number)
  9. toBigDecimal(final String bigdecimal)