Example usage for java.math BigDecimal compareTo

List of usage examples for java.math BigDecimal compareTo

Introduction

In this page you can find the example usage for java.math BigDecimal compareTo.

Prototype

@Override
public int compareTo(BigDecimal val) 

Source Link

Document

Compares this BigDecimal with the specified BigDecimal .

Usage

From source file:edu.ku.brc.specify.config.LatLonConverter.java

public static String convertToSignedDDDDDD(final BigDecimal dd, final int decimalLen,
        final DEGREES_FORMAT degFmt) {
    String sign = "";
    if (dd.compareTo(dd.abs()) < 0) {
        sign = "-";
    }//w w w.  j  av a 2s. co  m

    String convertedAbs = convertToDDDDDD(dd, degFmt, DIRECTION.None, decimalLen);
    return sign + convertedAbs;
}

From source file:edu.ku.brc.specify.config.LatLonConverter.java

/**
 * @param bd/*from w  w w  . j  a v a2  s  . c om*/
 * @param decimalLen
 * @param degFmt
 * @return
 */
public static String convertToSignedDDMMSS(final BigDecimal bd, final int decimalLen,
        final DEGREES_FORMAT degFmt) {
    String sign = "";
    if (bd.compareTo(bd.abs()) < 0) {
        sign = "-";
    }

    String convertedAbs = convertToDDMMSS(bd, degFmt, DIRECTION.None, decimalLen);
    return sign + convertedAbs;
}

From source file:edu.ku.brc.specify.config.LatLonConverter.java

/**
 * @param dd//  w  ww.  jav  a 2  s. c o m
 * @param decimalLen
 * @param degFmt
 * @return
 */
public static String convertToSignedDDMMMM(final BigDecimal dd, final int decimalLen,
        final DEGREES_FORMAT degFmt) {
    String sign = "";
    if (dd.compareTo(dd.abs()) < 0) {
        sign = "-";
    }

    String convertedAbs = convertToDDMMMM(dd, degFmt, DIRECTION.None, decimalLen);
    return sign + convertedAbs;
}

From source file:edu.ku.brc.util.LatLonConverter.java

/**
 * @param dd/*from ww  w. j a  v a2s  .c  o  m*/
 * @param decimalLen
 * @param detFmt
 * @return
 */
public static String convertToSignedDDDDDD(final BigDecimal dd, final int decimalLen,
        final DEGREES_FORMAT degFmt) {
    String sign = "";
    if (dd.compareTo(dd.abs()) < 0) {
        sign = "-";
    }

    String convertedAbs = convertToDDDDDD(dd, degFmt, DIRECTION.None, decimalLen);
    return sign + convertedAbs;
}

From source file:Main.java

/**
 * Compute e^x to a given scale. Break x into its whole and fraction parts
 * and compute (e^(1 + fraction/whole))^whole using Taylor's formula.
 * //from   ww  w . j  ava  2  s.com
 * @param x
 *            the value of x
 * @param scale
 *            the desired scale of the result
 * @return the result value
 */
public static BigDecimal exp(BigDecimal x, int scale) {
    // e^0 = 1
    if (x.signum() == 0) {
        return BigDecimal.valueOf(1);
    }

    // If x is negative, return 1/(e^-x).
    else if (x.signum() == -1) {
        return BigDecimal.valueOf(1).divide(exp(x.negate(), scale), scale, BigDecimal.ROUND_HALF_EVEN);
    }

    // Compute the whole part of x.
    BigDecimal xWhole = x.setScale(0, BigDecimal.ROUND_DOWN);

    // If there isn't a whole part, compute and return e^x.
    if (xWhole.signum() == 0) {
        return expTaylor(x, scale);
    }

    // Compute the fraction part of x.
    BigDecimal xFraction = x.subtract(xWhole);

    // z = 1 + fraction/whole
    BigDecimal z = BigDecimal.valueOf(1).add(xFraction.divide(xWhole, scale, BigDecimal.ROUND_HALF_EVEN));

    // t = e^z
    BigDecimal t = expTaylor(z, scale);

    BigDecimal maxLong = BigDecimal.valueOf(Long.MAX_VALUE);
    BigDecimal result = BigDecimal.valueOf(1);

    // Compute and return t^whole using intPower().
    // If whole > Long.MAX_VALUE, then first compute products
    // of e^Long.MAX_VALUE.
    while (xWhole.compareTo(maxLong) >= 0) {
        result = result.multiply(intPower(t, Long.MAX_VALUE, scale)).setScale(scale,
                BigDecimal.ROUND_HALF_EVEN);
        xWhole = xWhole.subtract(maxLong);

        Thread.yield();
    }
    return result.multiply(intPower(t, xWhole.longValue(), scale)).setScale(scale, BigDecimal.ROUND_HALF_EVEN);
}

From source file:com.github.fge.jsonschema.syntax.checkers.helpers.DivisorSyntaxChecker.java

@Override
protected void checkValue(final Collection<JsonPointer> pointers, final ProcessingReport report,
        final SchemaTree tree) throws ProcessingException {
    final JsonNode node = getNode(tree);
    final BigDecimal divisor = node.decimalValue();

    if (divisor.compareTo(BigDecimal.ZERO) <= 0)
        report.error(newMsg(tree, "illegalDivisor").put("found", node));
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.helpers.DivisorSyntaxChecker.java

@Override
protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle,
        final ProcessingReport report, final SchemaTree tree) throws ProcessingException {
    final JsonNode node = getNode(tree);
    final BigDecimal divisor = node.decimalValue();

    if (divisor.compareTo(BigDecimal.ZERO) <= 0)
        report.error(newMsg(tree, bundle, "common.divisor.notPositive").put("found", node));
}

From source file:gemlite.core.internal.index.compare.ComparatorImpl.java

private int compareBigDecimal(BigDecimal o1, BigDecimal o2) {
    return o1.compareTo(o2);

}

From source file:com.redhat.lightblue.crud.validator.MinMaxChecker.java

private int cmp(BigDecimal nodeValue, BigDecimal fieldValue) {
    return nodeValue.compareTo(fieldValue);
}

From source file:com.haulmont.cuba.gui.components.validators.DoubleValidator.java

private boolean checkBigDecimalOnPositive(BigDecimal value) {
    return !ObjectUtils.equals("true", onlyPositive) || value.compareTo(BigDecimal.ZERO) >= 0;
}