SQL <code>ROUND</code> operator applied to BigDecimal values.
426200
public static BigDecimal sround(BigDecimal b0, int b1) {
		return b0.movePointRight(b1)
			.setScale(0, RoundingMode.HALF_UP).movePointLeft(b1);
	}
714994
public BigDecimal roundBigDecimal(final BigDecimal number) {
    int mscale = getMathScale();
    if (mscale >= 0) {
      return number.setScale(mscale, getMathContext().getRoundingMode());
    }
    else {
      return number;
    }
  }
1285941
private BigDecimal round(BigDecimal amount) {
        return new BigDecimal(amount.movePointRight(2).add(new BigDecimal(".5")).toBigInteger()).movePointLeft(2);
    }
842966
@GwtIncompatible("TODO")
  public static BigInteger divide(BigInteger p, BigInteger q, RoundingMode mode) {
    BigDecimal pDec = new BigDecimal(p);
    BigDecimal qDec = new BigDecimal(q);
    return pDec.divide(qDec, 0, mode).toBigIntegerExact();
  }
1198121
private BigRational multiply(BigDecimal value) {
		BigDecimal n = numerator.multiply(value);
		BigDecimal d = denominator;
		return of(n, d);
	}
505921
protected final CALC operator(Class<? extends Operator> operator, String value, char decimalSeparator) {
        return operator(operator, new Num(value, decimalSeparator));
    }
384302
private static BigDecimal getBigDecimalOrNull(Object value) {
            if ( !(value instanceof Number || value instanceof String) ) {
                return null;
            }
            if ( !BigDecimal.class.isAssignableFrom( value.getClass() ) ) {
                if ( value instanceof Long || value instanceof Integer || value instanceof Short || value instanceof Byte ||
                     value instanceof AtomicLong || value instanceof AtomicInteger ) {
                    value = new BigDecimal( ((Number) value).longValue(), MathContext.DECIMAL128 );
                } else if ( value instanceof BigInteger ) {
                    value = new BigDecimal( ((BigInteger) value).toString(), MathContext.DECIMAL128 );
                } else if ( value instanceof String ) {
                    // we need to remove leading zeros to prevent octal conversion
                    value = new BigDecimal( ((String) value).replaceFirst("^0+(?!$)", ""), MathContext.DECIMAL128 );
                } else {
                    value = new BigDecimal( ((Number) value).doubleValue(), MathContext.DECIMAL128 );
                }
            }
            return (BigDecimal) value;
        }
485143
public BigDecimal getInternalBigDecimal(ColumnInformation columnInfo) throws SQLException {
    if (lastValueWasNull()) {
      return null;
    }

    switch (columnInfo.getColumnType()) {
      case BIT:
        return BigDecimal.valueOf(parseBit());
      case TINYINT:
        return BigDecimal.valueOf((long) getInternalTinyInt(columnInfo));
      case SMALLINT:
      case YEAR:
        return BigDecimal.valueOf((long) getInternalSmallInt(columnInfo));
      case INTEGER:
      case MEDIUMINT:
        return BigDecimal.valueOf(getInternalMediumInt(columnInfo));
      case BIGINT:
        long value = ((buf[pos] & 0xff)
            + ((long) (buf[pos + 1] & 0xff) << 8)
            + ((long) (buf[pos + 2] & 0xff) << 16)
            + ((long) (buf[pos + 3] & 0xff) << 24)
            + ((long) (buf[pos + 4] & 0xff) << 32)
            + ((long) (buf[pos + 5] & 0xff) << 40)
            + ((long) (buf[pos + 6] & 0xff) << 48)
            + ((long) (buf[pos + 7] & 0xff) << 56)
        );
        if (columnInfo.isSigned()) {
          return new BigDecimal(String.valueOf(BigInteger.valueOf(value)))
              .setScale(columnInfo.getDecimals());
        } else {
          return new BigDecimal(String.valueOf(new BigInteger(1, new byte[]{(byte) (value >> 56),
              (byte) (value >> 48), (byte) (value >> 40), (byte) (value >> 32),
              (byte) (value >> 24), (byte) (value >> 16), (byte) (value >> 8),
              (byte) value}))).setScale(columnInfo.getDecimals());
        }
      case FLOAT:
        return BigDecimal.valueOf(getInternalFloat(columnInfo));
      case DOUBLE:
        return BigDecimal.valueOf(getInternalDouble(columnInfo));
      case DECIMAL:
      case VARSTRING:
      case VARCHAR:
      case STRING:
      case OLDDECIMAL:
        return new BigDecimal(new String(buf, pos, length, StandardCharsets.UTF_8));
      default:
        throw new SQLException("getBigDecimal not available for data field type "
            + columnInfo.getColumnType().getJavaTypeName());
    }
  }
408343
def round(ndigits = 0)
      if_timezone_offset(super) {|o,t| self.class.at(t.to_i, t.subsec * 1_000_000).set_timezone_offset(o) }
    end
717902
public static NumberData round(SoyValue value, int numDigitsAfterPoint) {
    // NOTE: for more accurate rounding, this should really be using BigDecimal which can do correct
    // decimal arithmetic.  However, for compatibility with js, that probably isn't an option.
    if (numDigitsAfterPoint == 0) {
      return IntegerData.forValue(round(value));
    } else if (numDigitsAfterPoint > 0) {
      double valueDouble = value.numberValue();
      double shift = Math.pow(10, numDigitsAfterPoint);
      return FloatData.forValue(Math.round(valueDouble * shift) / shift);
    } else {
      double valueDouble = value.numberValue();
      double shift = Math.pow(10, -numDigitsAfterPoint);
      return IntegerData.forValue((int) (Math.round(valueDouble / shift) * shift));
    }
  }
448310
private static BigDecimal doRound128(long hi, long lo, int sign, int scale, MathContext mc) {
        int mcp = mc.precision;
        int drop;
        BigDecimal res = null;
        if(((drop = precision(hi, lo) - mcp) > 0)&&(drop<LONG_TEN_POWERS_TABLE.length)) {
            scale = checkScaleNonZero((long)scale - drop);
            res = divideAndRound128(hi, lo, LONG_TEN_POWERS_TABLE[drop], sign, scale, mc.roundingMode.oldMode, scale);
        }
        if(res!=null) {
            return doRound(res,mc);
        }
        return null;
    }
178087
public static BigDecimal roundToClosest(double value, double steps) {
        final BigDecimal down = DMatrixUtils.roundDownTo(value, steps);
        final BigDecimal up = DMatrixUtils.roundUpTo(value, steps);
        final BigDecimal orig = new BigDecimal(String.valueOf(value));
        if (orig.subtract(down).abs().compareTo(orig.subtract(up).abs()) < 0) {
            return down;
        }
        return up;
    }
799495
function round(float, digits) {
		if(digits == null) {
			return Math.round(float);
		}
		var round = 10 * digits;
		return Math.round(float * round) / round;
	}
881207
public BigDecimal getBigDecimal(int columnIndex) {
		Object fieldValue = data[columnIndex];
		if (fieldValue == null) {
			return null;
		}
		if (fieldValue instanceof BigDecimal) {
			return (BigDecimal) fieldValue;
		}
		throw new DBFException("Unsupported type for BigDecimal at column:" + columnIndex + " "
				+ fieldValue.getClass().getCanonicalName());
	}
748462
void setDecimal(final int parameterIndex, 
                    final BigDecimal x) throws SQLException {

        final ParameterDef def = (x == null) ? Decimal : Decimal(x);

        setParam(parameterIndex, def, x);
    }
816737
public static BigDecimal round(EvaluationContext ctx, Object number, Object numDigits) {
        BigDecimal _number = Conversions.toDecimal(number, ctx);
        int _numDigits = Conversions.toInteger(numDigits, ctx);

        return ExpressionUtils.decimalRound(_number, _numDigits, RoundingMode.HALF_UP);
    }
977127
public static double round(double d, int i) {
        double multiplier = Math.pow(10, i);
        return Math.round(d*multiplier)/multiplier;
    }