Example usage for org.apache.commons.lang3.math NumberUtils createBigDecimal

List of usage examples for org.apache.commons.lang3.math NumberUtils createBigDecimal

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils createBigDecimal.

Prototype

public static BigDecimal createBigDecimal(final String str) 

Source Link

Document

Convert a String to a BigDecimal.

Returns null if the string is null.

Usage

From source file:jp.furplag.spring.booster.validation.tuple.PairFractions.java

public PairFractions(Object left, Object right) {
    this((BigDecimal) (isCollectable(left) ? NumberUtils.createBigDecimal(Objects.toString(left, null)) : null),
            (BigDecimal) (isCollectable(right) ? NumberUtils.createBigDecimal(Objects.toString(right, null))
                    : null));//from   ww w  . j  av  a 2s. c  om
}

From source file:org.xlrnet.tibaija.util.ContextUtils.java

/**
 * Extracts the numerical value from a given NumberContext objects. This will always create a complex value.
 *
 * @param ctx//from w  w  w.jav  a 2 s . c o  m
 *         The NumberContext from the parser.
 * @return The numerical value as a complex object.
 */
public static Value extractValueFromNumberContext(TIBasicParser.NumberContext ctx) {
    boolean isNegative = !isNull(ctx.NEGATIVE_MINUS());
    boolean isDecimal = !isNull(ctx.DOT());
    String preDecimal = (StringUtils.isNotEmpty(ctx.preDecimal)) ? ctx.preDecimal : "0";
    String decimal = (StringUtils.isNotEmpty(ctx.decimal)) ? ctx.decimal : "0";

    BigDecimal value;
    if (isDecimal) {
        value = NumberUtils.createBigDecimal(preDecimal + "." + decimal);
    } else {
        if ("0".equals(preDecimal))
            value = NumberUtils.createBigDecimal(decimal);
        else
            value = NumberUtils.createBigDecimal(preDecimal + decimal);
    }

    if (isNegative)
        value = value.multiply(BigDecimal.valueOf(-1));

    return Value.of(value);
}