Tabnine Logo
BigDecimal.compareTo
Code IndexAdd Tabnine to your IDE (free)

How to use
compareTo
method
in
java.math.BigDecimal

Best Java code snippets using java.math.BigDecimal.compareTo (Showing top 20 results out of 10,854)

Refine searchRefine arrow

  • BigDecimal.<init>
  • BigInteger.compareTo
  • BigDecimal.add
  • BigDecimal.valueOf
  • BigDecimal.subtract
origin: stackoverflow.com

if (new BigDecimal(someprice).compareTo(BigDecimal.ZERO) == 0) // see below
origin: apache/incubator-druid

 private static int compareDoubleToLong(final double a, final long b)
 {
  // Use BigDecimal when comparing integers vs floating points, a convenient way to handle all cases (like
  // fractional values, values out of range of max long/max int) without worrying about them ourselves.
  return BigDecimal.valueOf(a).compareTo(BigDecimal.valueOf(b));
 }
}
origin: org.assertj/assertj-core

@Override
protected boolean isGreaterThan(BigDecimal value, BigDecimal other) {
 return value.subtract(other).compareTo(ZERO) > 0;
}
origin: apache/hive

 @Override
 public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo
     typeInfo) {
  List<MutablePair<String, String>> intervals = new ArrayList<>();
  DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo)typeInfo;
  int scale = decimalTypeInfo.getScale();
  BigDecimal decimalLower = new BigDecimal(lowerBound);
  BigDecimal decimalUpper = new BigDecimal(upperBound);
  BigDecimal decimalInterval = (decimalUpper.subtract(decimalLower)).divide(new BigDecimal(numPartitions),
      MathContext.DECIMAL64);
  BigDecimal splitDecimalLower, splitDecimalUpper;
  for (int i=0;i<numPartitions;i++) {
   splitDecimalLower = decimalLower.add(decimalInterval.multiply(new BigDecimal(i))).setScale(scale,
       RoundingMode.HALF_EVEN);
   splitDecimalUpper = decimalLower.add(decimalInterval.multiply(new BigDecimal(i+1))).setScale(scale,
       RoundingMode.HALF_EVEN);
   if (splitDecimalLower.compareTo(splitDecimalUpper) < 0) {
    intervals.add(new MutablePair<String, String>(splitDecimalLower.toPlainString(), splitDecimalUpper.toPlainString()));
   }
  }
  return intervals;
 }
}
origin: stackoverflow.com

 BigDecimal step = new BigDecimal("0.1");
for (BigDecimal value = BigDecimal.ZERO;
   value.compareTo(BigDecimal.ONE) < 0;
   value = value.add(step)) {
  System.out.println(value);
}
origin: org.codehaus.groovy/groovy

final BigDecimal one = BigDecimal.valueOf(10, 1);  // That's what you get for "1.0".
if (to instanceof BigDecimal) {
  BigDecimal to1 = (BigDecimal) to;
  if (self.compareTo(to1) <= 0) {
    for (BigDecimal i = self; i.compareTo(to1) <= 0; i = i.add(one)) {
      closure.call(i);
        ") to upto() cannot be less than the value (" + self + ") it's called on.");
} else if (to instanceof BigInteger) {
  BigDecimal to1 = new BigDecimal((BigInteger) to);
  if (self.compareTo(to1) <= 0) {
    for (BigDecimal i = self; i.compareTo(to1) <= 0; i = i.add(one)) {
      closure.call(i);
        ") to upto() cannot be less than the value (" + self + ") it's called on.");
} else {
  BigDecimal to1 = new BigDecimal(to.toString());
  if (self.compareTo(to1) <= 0) {
    for (BigDecimal i = self; i.compareTo(to1) <= 0; i = i.add(one)) {
      closure.call(i);
origin: org.codehaus.groovy/groovy

final BigDecimal one = BigDecimal.valueOf(10, 1);  // Quick way to get "1.0".
if (to instanceof BigDecimal) {
  BigDecimal to1 = (BigDecimal) to;
  if (self.compareTo(to1) >= 0) {
    for (BigDecimal i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) {
      closure.call(i);
    throw new GroovyRuntimeException("The argument (" + to +
        ") to downto() cannot be greater than the value (" + self + ") it's called on.");        } else if (to instanceof BigInteger) {
  BigDecimal to1 = new BigDecimal((BigInteger) to);
  if (self.compareTo(to1) >= 0) {
    for (BigDecimal i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) {
      closure.call(i);
    throw new GroovyRuntimeException("The argument (" + to +
        ") to downto() cannot be greater than the value (" + self + ") it's called on.");        } else {
  BigDecimal to1 = new BigDecimal(to.toString());
  if (self.compareTo(to1) >= 0) {
    for (BigDecimal i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) {
      closure.call(i);
origin: spring-projects/spring-framework

BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
return (leftBigDecimal.compareTo(rightBigDecimal) == 0);
BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class);
BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class);
return (leftBigInteger.compareTo(rightBigInteger) == 0);
origin: apache/hive

/**
 * Calculate difference between values in percent
 */
public BigDecimal percentDiff(Var var) {
 BigDecimal d1 = new Var(Var.Type.DECIMAL).cast(this).decimalValue();
 BigDecimal d2 = new Var(Var.Type.DECIMAL).cast(var).decimalValue();
 if (d1 != null && d2 != null) {
  if (d1.compareTo(BigDecimal.ZERO) != 0) {
   return d1.subtract(d2).abs().multiply(new BigDecimal(100)).divide(d1, 2, RoundingMode.HALF_UP);
  }
 }
 return null;
}
 
origin: json-path/JsonPath

private static Number unwrapNumber(final Number n) {
  Number unwrapped;
  if (!isPrimitiveNumber(n)) {
    BigDecimal bigDecimal = new BigDecimal(n.toString());
    if (bigDecimal.scale() <= 0) {
      if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
        unwrapped = bigDecimal.intValue();
      } else if (bigDecimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
        unwrapped = bigDecimal.longValue();
      } else {
        unwrapped = bigDecimal;
      }
    } else {
      final double doubleValue = bigDecimal.doubleValue();
      if (BigDecimal.valueOf(doubleValue).compareTo(bigDecimal) != 0) {
        unwrapped = bigDecimal;
      } else {
        unwrapped = doubleValue;
      }
    }
  } else {
    unwrapped = n;
  }
  return unwrapped;
}
origin: plantuml/plantuml

  public BigDecimal eval(List<? extends Number> parameters) {
    assertNotNull(parameters.get(0));
    /*
     * From The Java Programmers Guide To numerical Computing (Ronald Mak, 2003)
     */
    BigDecimal x = (BigDecimal) parameters.get(0);
    if (x.compareTo(BigDecimal.ZERO) == 0) {
      return new BigDecimal(0);
    }
    if (x.signum() < 0) {
      throw new ExpressionException("Argument to SQRT() function must not be negative");
    }
    BigInteger n = x.movePointRight(mc.getPrecision() << 1).toBigInteger();
    int bits = (n.bitLength() + 1) >> 1;
    BigInteger ix = n.shiftRight(bits);
    BigInteger ixPrev;
    BigInteger test;
    do {
      ixPrev = ix;
      ix = ix.add(n.divide(ix)).shiftRight(1);
      // Give other threads a chance to work;
      Thread.yield();
      test = ix.subtract(ixPrev).abs();
    } while (test.compareTo(BigInteger.ZERO) != 0 && test.compareTo(BigInteger.ONE) != 0);
    return new BigDecimal(ix, mc.getPrecision());
  }
});
origin: stackoverflow.com

  return BigDecimal.valueOf(magnitude).multiply(lnRoot)
        .setScale(scale, BigDecimal.ROUND_HALF_EVEN);
BigDecimal tolerance = BigDecimal.valueOf(5)
                  .movePointLeft(sp1);
  term = eToX.subtract(n)
        .divide(eToX, sp1, BigDecimal.ROUND_DOWN);
  x = x.subtract(term);
} while (term.compareTo(tolerance) > 0);
origin: openhab/openhab1-addons

/**
 * Canonicalize the current latitude and longitude values such that:
 *
 * <pre>
 * -90 &lt;= latitude &lt;= +90 - 180 &lt; longitude &lt;= +180
 * </pre>
 */
private void canonicalize(DecimalType aLat, DecimalType aLon) {
  latitude = flat.add(aLat.toBigDecimal()).remainder(circle);
  longitude = aLon.toBigDecimal();
  if (latitude.compareTo(BigDecimal.ZERO) == -1) {
    latitude.add(circle);
  }
  latitude = latitude.subtract(flat);
  if (latitude.compareTo(right) == 1) {
    latitude = flat.subtract(latitude);
    longitude = longitude.add(flat);
  } else if (latitude.compareTo(right.negate()) == -1) {
    latitude = flat.negate().subtract(latitude);
    longitude = longitude.add(flat);
  }
  longitude = flat.add(longitude).remainder(circle);
  if (longitude.compareTo(BigDecimal.ZERO) <= 0) {
    longitude = longitude.add(circle);
  }
  longitude = longitude.subtract(flat);
}
origin: debezium/debezium

  /**
   * Convert original value insertion of type 'BIGINT' into the correct BIGINT UNSIGNED representation
   * Note: Unsigned BIGINT (16-bit) is represented in 'BigDecimal' data type. Reference: https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Schema.Type.html
   *
   * @param originalNumber {@link BigDecimal} the original insertion value
   * @return {@link BigDecimal} the correct representation of the original insertion value
   */
  public static BigDecimal convertUnsignedBigint(BigDecimal originalNumber) {
    if (originalNumber.compareTo(BigDecimal.ZERO) == -1) {
      return originalNumber.add(BIGINT_CORRECTION);
    } else {
      return originalNumber;
    }
  }
}
origin: jphp-group/jphp

private static BigDecimal bcpowImpl(BigDecimal base, BigInteger exp, int scale) {
  if (exp.compareTo(BigInteger.ZERO) == 0)
    return BigDecimal.ONE;
  boolean isNeg;
  if (exp.compareTo(BigInteger.ZERO) < 0) {
    isNeg = true;
    exp = exp.negate();
  }
  else
    isNeg = false;
  BigDecimal result = BigDecimal.ZERO;
  while (exp.compareTo(BigInteger.ZERO) > 0) {
    BigInteger expSub = exp.min(INTEGER_MAX);
    exp = exp.subtract(expSub);
    result = result.add(base.pow(expSub.intValue()));
  }
  if (isNeg)
    result = BigDecimal.ONE.divide(result, scale + 2, RoundingMode.DOWN);
  result = result.setScale(scale, RoundingMode.DOWN);
  if (result.compareTo(BigDecimal.ZERO) == 0)
    return BigDecimal.ZERO;
  result = result.stripTrailingZeros();
  return result;
}
origin: openhab/openhab1-addons

private void validateValue(BigDecimal value) {
  if (BigDecimal.ZERO.compareTo(value) > 0 || new BigDecimal(100).compareTo(value) < 0) {
    throw new IllegalArgumentException("Value must be between 0 and 100");
  }
}
origin: knowm/XChange

public static LimitOrder adaptOrder(CexIOFullOrder cexIOOrder) {
 OrderType orderType = cexIOOrder.type.equals("sell") ? OrderType.ASK : OrderType.BID;
 BigDecimal originalAmount = new BigDecimal(cexIOOrder.amount);
 CurrencyPair currencyPair = new CurrencyPair(cexIOOrder.symbol1, cexIOOrder.symbol2);
 Date timestamp = new Date(cexIOOrder.time);
 BigDecimal limitPrice = new BigDecimal(cexIOOrder.price);
 Order.OrderStatus status = adaptOrderStatus(cexIOOrder);
 BigDecimal cumulativeAmount = null;
  BigDecimal remains = new BigDecimal(cexIOOrder.remains);
  cumulativeAmount = originalAmount.subtract(remains);
     ? new BigDecimal(cexIOOrder.totalAmountTaker)
     : BigDecimal.ZERO;
 BigDecimal tradedAmount = totalAmountMaker.add(totalAmountTaker);
 if (cumulativeAmount != null && tradedAmount.compareTo(BigDecimal.ZERO) > 0) {
  averagePrice = tradedAmount.divide(cumulativeAmount, 2, RoundingMode.HALF_UP);
 BigDecimal feeTaker =
   cexIOOrder.feeTaker != null ? new BigDecimal(cexIOOrder.feeTaker) : BigDecimal.ZERO;
 BigDecimal fee = feeMaker.add(feeTaker);
 return new LimitOrder(
   orderType,
   averagePrice,
   cumulativeAmount,
   fee.compareTo(BigDecimal.ZERO) > 0 ? fee : null,
   status);
origin: deeplearning4j/nd4j

if (x.compareTo(BigDecimal.ZERO) < 0) {
  return cos(x.negate());
} else if (x.compareTo(BigDecimal.ZERO) == 0) {
  return BigDecimal.ONE;
} else {
      ifac = ifac.multiply(BigInteger.valueOf(2 * i));
      xpowi = xpowi.multiply(xhighpr).multiply(xhighpr);
      BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
      resul = resul.add(corr);
origin: org.codehaus.groovy/groovy

final BigDecimal one = BigDecimal.valueOf(10, 1);
BigDecimal self1 = new BigDecimal(self);
BigDecimal to1 = (BigDecimal) to;
if (self1.compareTo(to1) <= 0) {
  for (BigDecimal i = self1; i.compareTo(to1) <= 0; i = i.add(one)) {
    closure.call(i);
final BigInteger one = BigInteger.valueOf(1);
BigInteger to1 = (BigInteger) to;
if (self.compareTo(to1) <= 0) {
  for (BigInteger i = self; i.compareTo(to1) <= 0; i = i.add(one)) {
    closure.call(i);
final BigInteger one = BigInteger.valueOf(1);
BigInteger to1 = new BigInteger(to.toString());
if (self.compareTo(to1) <= 0) {
  for (BigInteger i = self; i.compareTo(to1) <= 0; i = i.add(one)) {
    closure.call(i);
origin: org.codehaus.groovy/groovy

final BigDecimal one = BigDecimal.valueOf(10, 1);  // That's what you get for "1.0".
final BigDecimal to1 = (BigDecimal) to;
final BigDecimal selfD = new BigDecimal(self);
if (selfD.compareTo(to1) >= 0) {
  for (BigDecimal i = selfD; i.compareTo(to1) >= 0; i = i.subtract(one)) {
    closure.call(i.toBigInteger());
final BigInteger one = BigInteger.valueOf(1);
final BigInteger to1 = (BigInteger) to;
if (self.compareTo(to1) >= 0) {
  for (BigInteger i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) {
    closure.call(i);
final BigInteger one = BigInteger.valueOf(1);
final BigInteger to1 = new BigInteger(to.toString());
if (self.compareTo(to1) >= 0) {
  for (BigInteger i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) {
    closure.call(i);
java.mathBigDecimalcompareTo

Javadoc

Compares this BigDecimal with the specified Object. If the Object is a BigDecimal, this method behaves like #compareTo. Otherwise, it throws a ClassCastException (as BigDecimals are comparable only to other BigDecimals).

Popular methods of BigDecimal

  • <init>
    Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same se
  • valueOf
  • doubleValue
    Converts this BigDecimal to a double. This conversion is similar to thenarrowing primitive conversio
  • setScale
    Returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by m
  • divide
  • add
  • multiply
  • toString
    Returns the string representation of this BigDecimal, using scientific notation if an exponent is ne
  • subtract
    Returns a BigDecimal whose value is (this - subtrahend), with rounding according to the context sett
  • intValue
    Converts this BigDecimal to an int. This conversion is analogous to thenarrowing primitive conversio
  • longValue
    Converts this BigDecimal to a long. This conversion is analogous to thenarrowing primitive conversio
  • toPlainString
    Returns a string representation of this BigDecimalwithout an exponent field. For values with a posit
  • longValue,
  • toPlainString,
  • scale,
  • toBigInteger,
  • equals,
  • floatValue,
  • negate,
  • unscaledValue,
  • abs

Popular in Java

  • Finding current android device location
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • onRequestPermissionsResult (Fragment)
  • setRequestProperty (URLConnection)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Kernel (java.awt.image)
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • JComboBox (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now