Package org.apache.calcite.util
Class NumberUtil
java.lang.Object
org.apache.calcite.util.NumberUtil
Utility functions for working with numbers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @PolyNull DoubleReturns the sum of two numbers, or null if either is null.static DecimalFormatdecimalFormat(String pattern) Creates a format.static @Nullable DoubleReturns the quotient of two numbers, or null if either is null or the divisor is zero.static NumberFormatgetApproxFormatter(boolean isFloat) static BigIntegergetMaxUnscaled(int precision) static BigIntegergetMinUnscaled(int precision) static booleanReturns whether aBigDecimalis a valid Farrago decimal.static @PolyNull DoubleLikeMath.max(int, int)but null safe; returns the greater of two numbers, or null if either is null.static @PolyNull DoubleLikeMath.min(int, int)but null safe; returns the lesser of two numbers, ignoring numbers that are null, or null if both are null.static @PolyNull DoubleReturns the product of two numbers, or null if either is null.static BigIntegerpowTen(int exponent) static @PolyNull BigDecimalrescaleBigDecimal(@PolyNull BigDecimal bd, int scale) Sets the scale of a BigDecimalbdif it is not null; always returnsbd.static longround(double d) static @PolyNull DoubleReturns the difference of two numbers, or null if either is null.static @PolyNull BigDecimaltoBigDecimal(@PolyNull Number number) Converts a number to a BigDecimal with the same value; returns null if and only if the number is null.static BigDecimaltoBigDecimal(Number number, int scale)
-
Method Details
-
decimalFormat
Creates a format. Locale-independent. -
powTen
-
getMaxUnscaled
-
getMinUnscaled
-
rescaleBigDecimal
Sets the scale of a BigDecimalbdif it is not null; always returnsbd. -
toBigDecimal
-
toBigDecimal
Converts a number to a BigDecimal with the same value; returns null if and only if the number is null. -
isValidDecimal
Returns whether aBigDecimalis a valid Farrago decimal. If a BigDecimal's unscaled value overflows a long, then it is not a valid Farrago decimal. -
getApproxFormatter
-
round
public static long round(double d) -
add
Returns the sum of two numbers, or null if either is null. -
subtract
Returns the difference of two numbers, or null if either is null. -
divide
Returns the quotient of two numbers, or null if either is null or the divisor is zero. -
multiply
Returns the product of two numbers, or null if either is null. -
min
LikeMath.min(int, int)but null safe; returns the lesser of two numbers, ignoring numbers that are null, or null if both are null. -
max
LikeMath.max(int, int)but null safe; returns the greater of two numbers, or null if either is null.
-