Java Utililty Methods BigDecimal Create

List of utility methods to do BigDecimal Create

Description

The list of methods to do BigDecimal Create are organized into topic(s).

Method

BigDecimalgetBigDecimalOrNull(Object value)
get Big Decimal Or Null
if (!(value instanceof Number || value instanceof String)) {
    return null;
if (!BigDecimal.class.isAssignableFrom(value.getClass())) {
    if (value instanceof Long || value instanceof Integer || value instanceof Short || value instanceof Byte
            || value instanceof AtomicLong || value instanceof AtomicInteger) {
        value = new BigDecimal(((Number) value).longValue(), MathContext.DECIMAL128);
    } else if (value instanceof BigInteger) {
...
BigDecimalgetBigDecimalValue(Object o)
Converts an object to a BigDecimal using the string representation of the object.
if (o != null && o.toString().length() > 0) {
    return new BigDecimal(o.toString());
} else {
    return null;
doublegetDecimal(double a)
get Decimal
BigDecimal bd = new BigDecimal(a);
bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
StringgetDecimal(Object[] data, int ordinal)
get decimal data type data by ordinal This is for C++ SDK JNI don't support Decimal, so carbon convert decimal to string
return ((BigDecimal) data[ordinal]).toString();
voidgetDecimal(String clusive, int[] currentDecimal)
get Decimal
int length = 0;
int decimal = 0;
if (clusive != null && clusive.length() > 0) {
    try {
        BigDecimal bd = new BigDecimal(clusive);
        length = (bd.abs().toPlainString().length() + (bd.scale() > 0 ? -1 : 0));
        if (bd.scale() > 0) {
            decimal = bd.scale();
...
BigDecimalgetDecimal(String number, BigDecimal def)
Parse the given string into a big decimal if possible otherwise return the specified default.
try {
    return new BigDecimal(number);
} catch (Exception e) {
    return def;
DoublegetDecimalCoords(Integer degrees, Integer minutes, Integer seconds)
Convert DMS format coordinate into decimal degrees, where W and S are indicated by negative degrees.
Double deg = null;
Double min = null;
Double sec = null;
if (degrees != null) {
    deg = Double.valueOf(degrees);
if (minutes != null) {
    min = Double.valueOf(minutes);
...
NumbergetDecimalValue(String value, Object franctionDigits)
get Decimal Value
if (value == null || "".equals(value)) {
    return null;
BigDecimal bigdecimal = new BigDecimal(value);
if (franctionDigits != null && !franctionDigits.equals("")) {
    return bigdecimal.setScale(Integer.parseInt(franctionDigits.toString()), RoundingMode.HALF_UP);
return bigdecimal.setScale(2, RoundingMode.HALF_UP);
...
BigDecimal[]getDecimalValues(String[] values, String dataType)
get Decimal Values
String[] dataArr = getValues(values, dataType);
BigDecimal[] valueArr = new BigDecimal[dataArr.length];
int i = 0;
for (String data : dataArr) {
    valueArr[i++] = new BigDecimal(data);
return valueArr;
BigDecimalnullToBigDecimalZero(final Object obj)
null To Big Decimal Zero
if (obj == null || "".equals(obj.toString())) {
    return new BigDecimal("0");
} else {
    return new BigDecimal(obj.toString());