Here you can find the source of bigDecimalValueOf(Number n)
Parameter | Description |
---|---|
n | an instance of java.lang.Number to be converted. |
public static BigDecimal bigDecimalValueOf(Number n)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; import java.math.BigInteger; public class Main { /**/* w ww . j av a 2 s .c o m*/ * Converts a number into its BigDecimal equivalent. Useful for comparisons * between Numbers. * * @param n an instance of java.lang.Number to be converted. * @return BigDecimal equivalent of n. */ public static BigDecimal bigDecimalValueOf(Number n) { if (n instanceof BigDecimal) { return (BigDecimal) n; } else if (n instanceof BigInteger) { return new BigDecimal((BigInteger) n); } else if (n instanceof Double) { return new BigDecimal((Double) n); } else if (n instanceof Float) { return new BigDecimal((Float) n); } else { return n == null ? null : new BigDecimal(n.longValue()); } } }