Java BigDecimal Create bigDecimal(Number num)

Here you can find the source of bigDecimal(Number num)

Description

big Decimal

License

Apache License

Declaration

public static BigDecimal bigDecimal(Number num) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
    public static BigDecimal bigDecimal(Number num) {
        if (num == null)
            throw new NullPointerException();
        if (num instanceof BigDecimal)
            return (BigDecimal) num;
        if (num instanceof BigInteger)
            return new BigDecimal((BigInteger) num);
        if (num instanceof Byte)
            return new BigDecimal((Byte) num);
        if (num instanceof Double)
            return new BigDecimal((Double) num);
        if (num instanceof Float)
            return new BigDecimal((Float) num);
        if (num instanceof Integer)
            return new BigDecimal((Integer) num);
        if (num instanceof Long)
            return new BigDecimal((Long) num);
        if (num instanceof Short)
            return new BigDecimal((Short) num);
        String message = String.format("Unsupported number object %s(%s) is given.", num, num.getClass());
        throw new IllegalArgumentException(message);
    }/* ww w . j  av a  2  s.  c  o  m*/
}

Related

  1. bigDecimal(Object object)
  2. bigDecimalFromBytes(byte[] decimalBytes, int scale)
  3. bigDecimalFromString(String s)
  4. bigDecimalValue(final Number number)