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 Double
Returns the sum of two numbers, or null if either is null.static DecimalFormat
decimalFormat
(String pattern) Creates a format.static @Nullable Double
Returns the quotient of two numbers, or null if either is null or the divisor is zero.static NumberFormat
getApproxFormatter
(boolean isFloat) static BigInteger
getMaxUnscaled
(int precision) static BigInteger
getMinUnscaled
(int precision) static boolean
Returns whether aBigDecimal
is a valid Farrago decimal.static @PolyNull Double
LikeMath.max(int, int)
but null safe; returns the greater of two numbers, or null if either is null.static @PolyNull Double
LikeMath.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 Double
Returns the product of two numbers, or null if either is null.static BigInteger
powTen
(int exponent) static @PolyNull BigDecimal
rescaleBigDecimal
(@PolyNull BigDecimal bd, int scale) Sets the scale of a BigDecimalbd
if it is not null; always returnsbd
.static long
round
(double d) static @PolyNull Double
Returns the difference of two numbers, or null if either is null.static @PolyNull BigDecimal
toBigDecimal
(@PolyNull Number number) Converts a number to a BigDecimal with the same value; returns null if and only if the number is null.static BigDecimal
toBigDecimal
(Number number, int scale)
-
Method Details
-
decimalFormat
Creates a format. Locale-independent. -
powTen
-
getMaxUnscaled
-
getMinUnscaled
-
rescaleBigDecimal
Sets the scale of a BigDecimalbd
if 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 aBigDecimal
is 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.
-