Java BigDecimal from toBigDecimal(JsonValue val)

Here you can find the source of toBigDecimal(JsonValue val)

Description

to Big Decimal

License

Open Source License

Declaration

public static BigDecimal toBigDecimal(JsonValue val) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

import java.util.function.Function;

import javax.json.JsonNumber;

import javax.json.JsonString;
import javax.json.JsonValue;

public class Main {

    public static BigDecimal toBigDecimal(JsonValue val) {
        if (val instanceof JsonNumber) {
            return ((JsonNumber) val).bigDecimalValue();
        }/*from  w ww.  ja v  a 2  s .c  om*/
        return new BigDecimal(toString(val));
    }

    public static String toString(JsonValue val) {
        return toObject(val, v -> {
            if (v instanceof JsonString) {
                return ((JsonString) v).getString();
            }
            return v.toString();
        });
    }

    public static <T extends JsonValue, R> R toObject(T val, Function<T, R> function) {
        if (val == null || val == JsonValue.NULL) {
            return null;
        }
        return function.apply(val);
    }
}

Related

  1. toBigDecimal(final Number number)
  2. toBigDecimal(final String bigdecimal)
  3. toBigDecimal(final String string)
  4. toBigDecimal(final String value)
  5. toBigDecimal(Integer num)
  6. toBigDecimal(long seconds, int nanoseconds)
  7. toBigDecimal(Number n)
  8. toBigDecimal(Number n)
  9. toBigDecimal(Number n)