Class NumberUtil


public class NumberUtil extends Object
Utility functions for working with numbers.
  • Method Details

    • decimalFormat

      public static DecimalFormat decimalFormat(String pattern)
      Creates a format. Locale-independent.
    • powTen

      public static BigInteger powTen(int exponent)
    • getMaxUnscaled

      public static BigInteger getMaxUnscaled(int precision)
    • getMinUnscaled

      public static BigInteger getMinUnscaled(int precision)
    • rescaleBigDecimal

      public static @PolyNull BigDecimal rescaleBigDecimal(@PolyNull BigDecimal bd, int scale)
      Sets the scale of a BigDecimal bd if it is not null; always returns bd.
    • toBigDecimal

      public static BigDecimal toBigDecimal(Number number, int scale)
    • toBigDecimal

      public 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.
    • isValidDecimal

      public static boolean isValidDecimal(BigDecimal bd)
      Returns whether a BigDecimal is a valid Farrago decimal. If a BigDecimal's unscaled value overflows a long, then it is not a valid Farrago decimal.
    • getApproxFormatter

      public static NumberFormat getApproxFormatter(boolean isFloat)
    • round

      public static long round(double d)
    • add

      public static @PolyNull Double add(@PolyNull Double a, @PolyNull Double b)
      Returns the sum of two numbers, or null if either is null.
    • subtract

      public static @PolyNull Double subtract(@PolyNull Double a, @PolyNull Double b)
      Returns the difference of two numbers, or null if either is null.
    • divide

      public static @Nullable Double divide(@Nullable Double a, @Nullable Double b)
      Returns the quotient of two numbers, or null if either is null or the divisor is zero.
    • multiply

      public static @PolyNull Double multiply(@PolyNull Double a, @PolyNull Double b)
      Returns the product of two numbers, or null if either is null.
    • min

      public static @PolyNull Double min(@PolyNull Double a, @PolyNull Double b)
      Like Math.min(int, int) but null safe; returns the lesser of two numbers, ignoring numbers that are null, or null if both are null.
    • max

      public static @PolyNull Double max(@PolyNull Double a, @PolyNull Double b)
      Like Math.max(int, int) but null safe; returns the greater of two numbers, or null if either is null.