Java BigDecimal from toBigDecimal(final Number number)

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

Description

to Big Decimal

License

Apache License

Declaration

public static BigDecimal toBigDecimal(final Number number) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    public static BigDecimal toBigDecimal(final Number number) {
        if (number == null) {
            return null;
        } else if (number instanceof BigDecimal) {
            return (BigDecimal) number;
        } else if (number instanceof Byte) {
            return new BigDecimal((Byte) number);
        } else if (number instanceof Short) {
            return new BigDecimal((Short) number);
        } else if (number instanceof Integer) {
            return new BigDecimal((Integer) number);
        } else if (number instanceof Long) {
            return new BigDecimal((Long) number);
        } else if (number instanceof Float) {
            return new BigDecimal((Float) number);
        } else if (number instanceof Double) {
            return new BigDecimal((Double) number);
        } else {//from w  w w.  j  a  v a  2  s.  c  om
            return null;
        }
    }
}

Related

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