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

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

Introduction

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

Prototype

public static Number createNumber(final String str) throws NumberFormatException 

Source Link

Document

Turns a string value into a java.lang.Number.

If the string starts with 0x or -0x (lower or upper case) or # or -# , it will be interpreted as a hexadecimal Integer - or Long, if the number of digits after the prefix is more than 8 - or BigInteger if there are more than 16 digits.

Usage

From source file:org.xwiki.rendering.internal.macro.chart.source.AxisConfigurator.java

/**
 * Set the limits of a number axis.//from   ww  w .  j  a v a  2s.  com
 *
 * @param axis The axis.
 * @param index The index of the axis
 * @throws MacroExecutionException if the parameters could not be parsed as numbers.
 */
private void setNumberLimits(ValueAxis axis, int index) throws MacroExecutionException {
    try {
        if (axisLowerLimit[index] != null) {
            Number number = NumberUtils.createNumber(StringUtils.trim(axisLowerLimit[index]));
            axis.setLowerBound(number.doubleValue());
        }
        if (axisUpperLimit[index] != null) {
            Number number = NumberUtils.createNumber(StringUtils.trim(axisUpperLimit[index]));
            axis.setUpperBound(number.doubleValue());
        }
    } catch (NumberFormatException e) {
        throw new MacroExecutionException("Invalid number in axis bound.", e);
    }
}

From source file:org.xwiki.rendering.internal.macro.chart.source.table.AbstractTableBlockDataSource.java

/**
 * Tries to parse the cell content as a number.
 *
 * @param cell the {@link TableCellBlock}.
 * @return cell content parsed as a {@link Number}.
 * @throws MacroExecutionException if the cell does not represent a number.
 *//*w ww  .j a  v  a2  s.c  o  m*/
private Number cellContentAsNumber(TableCellBlock cell) throws MacroExecutionException {
    String stringContent = cellContentAsString(cell);
    try {
        return NumberUtils.createNumber(StringUtils.trim(stringContent));
    } catch (NumberFormatException ex) {
        throw new MacroExecutionException(String.format("Invalid number: [%s].", stringContent));
    }
}