Java Utililty Methods BigDecimal

List of utility methods to do BigDecimal

Description

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

Method

BigDecimalgetFloatingPoint(Console console, Function validator)
get Floating Point
if (validator == null)
    validator = value -> true;
String answer;
BigDecimal value;
do {
    answer = readLine(console);
    try {
        value = stripAndOrRescale(new BigDecimal(answer));
...
StringgetFormattedBigDecimal(BigDecimal value)
get Formatted Big Decimal
if (value.compareTo(DISPLAY_MAX) > 0) {
    return "very high";
int unitIndex = 0;
for (; unitIndex < UNIT.length && value.compareTo(THOUSAND) > 0; unitIndex++) {
    value = value.divide(THOUSAND);
if (unitIndex == 0) {
...
BigDecimalgetFraction(BigDecimal b)
get Fraction
return b.abs().subtract(b.abs().setScale(0, BigDecimal.ROUND_FLOOR).abs()).abs();
BigDecimalgetFractionalPart(BigDecimal value)
get Fractional Part
if (value == null) {
    return value;
BigDecimal fractionalPart = value.subtract(value.setScale(0, RoundingMode.FLOOR));
return (fractionalPart.compareTo(BigDecimal.ZERO) != 0) ? fractionalPart : null;
BigDecimalgetId(BigDecimal total, BigDecimal step)
get Id
return step.multiply(new BigDecimal(RANDOM.nextInt(total.intValue())));
intgetIntLength(BigDecimal val)
The digit number of an integer part is acquired.
BigInteger intVal = val.unscaledValue();
intVal = intVal.abs();
String bak = intVal.toString();
return bak.length();
intgetIntValue(BigDecimal b)
get Int Value
if (b == null) {
    return 0;
return b.intValue();
intgetLength(BigDecimal v)
get Length
int signum = v.signum();
if (signum == 0) { 
    return 1;
return (signum < 0 ? 2 : 1) + (v.precision() + 1 + (v.scale() % 2 == 0 ? 0 : 1)) / 2;
BigDecimalgetLet(BigDecimal nl, BigDecimal el)
get Let
BigDecimal lat_jp = getLetJp(nl);
BigDecimal lon_jp = getLonJp(el);
return lat_jp.subtract(lat_jp.multiply(new BigDecimal(0.00010695)))
        .add(lon_jp.multiply(new BigDecimal(0.000017464))).add(new BigDecimal(0.0046017))
        .setScale(7, BigDecimal.ROUND_HALF_UP);
BigDecimalgetLetJp(BigDecimal nl)
get Let Jp
return nl.divide(new BigDecimal(3600000), 7, BigDecimal.ROUND_HALF_UP);