Class NumberUtil

  • public class NumberUtil
    extends java.lang.Object
    Utility functions for working with numbers.
    • Constructor Summary

      Modifier Constructor Description
      private NumberUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Double add​(java.lang.Double a, java.lang.Double b)  
      static java.text.DecimalFormat decimalFormat​(java.lang.String pattern)
      Creates a format.
      static java.lang.Double divide​(java.lang.Double a, java.lang.Double b)  
      static java.text.NumberFormat getApproxFormatter​(boolean isFloat)  
      static java.math.BigInteger getMaxUnscaled​(int precision)  
      static java.math.BigInteger getMinUnscaled​(int precision)  
      static boolean isValidDecimal​(java.math.BigDecimal bd)  
      static java.lang.Double min​(java.lang.Double a, java.lang.Double b)
      Like Math.min(int, int) but null safe.
      static java.lang.Double multiply​(java.lang.Double a, java.lang.Double b)  
      static java.math.BigInteger powTen​(int exponent)  
      static java.math.BigDecimal rescaleBigDecimal​(java.math.BigDecimal bd, int scale)  
      static long round​(double d)  
      static java.math.BigDecimal toBigDecimal​(java.lang.Number number)  
      static java.math.BigDecimal toBigDecimal​(java.lang.Number number, int scale)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail


        private static final java.text.DecimalFormat FLOAT_FORMATTER

        private static final java.text.DecimalFormat DOUBLE_FORMATTER

        private static final java.math.BigInteger[] BIG_INT_TEN_POW

        private static final java.math.BigInteger[] BIG_INT_MIN_UNSCALED

        private static final java.math.BigInteger[] BIG_INT_MAX_UNSCALED
    • Constructor Detail

      • NumberUtil

        private NumberUtil()
    • Method Detail

      • decimalFormat

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

        public static java.math.BigInteger powTen​(int exponent)
      • getMaxUnscaled

        public static java.math.BigInteger getMaxUnscaled​(int precision)
      • getMinUnscaled

        public static java.math.BigInteger getMinUnscaled​(int precision)
      • rescaleBigDecimal

        public static java.math.BigDecimal rescaleBigDecimal​(java.math.BigDecimal bd,
                                                             int scale)
      • toBigDecimal

        public static java.math.BigDecimal toBigDecimal​(java.lang.Number number,
                                                        int scale)
      • toBigDecimal

        public static java.math.BigDecimal toBigDecimal​(java.lang.Number number)
      • isValidDecimal

        public static boolean isValidDecimal​(java.math.BigDecimal bd)
        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 java.text.NumberFormat getApproxFormatter​(boolean isFloat)
      • round

        public static long round​(double d)
      • add

        public static java.lang.Double add​(java.lang.Double a,
                                           java.lang.Double b)
      • divide

        public static java.lang.Double divide​(java.lang.Double a,
                                              java.lang.Double b)
      • multiply

        public static java.lang.Double multiply​(java.lang.Double a,
                                                java.lang.Double b)
      • min

        public static java.lang.Double min​(java.lang.Double a,
                                           java.lang.Double b)
        Like Math.min(int, int) but null safe.