Class NumberUtil

java.lang.Object
org.nuiton.util.NumberUtil

public class NumberUtil extends Object
Since:
3.0
Author:
Kevin Morin - morin@codelutin.com
  • Field Details

    • NULL_OR_ZERO_INTEGER

      public static final com.google.common.base.Predicate<Integer> NULL_OR_ZERO_INTEGER
    • NULL_OR_ZERO_FLOAT_ONE_DIGIT

      public static final com.google.common.base.Predicate<Float> NULL_OR_ZERO_FLOAT_ONE_DIGIT
    • NULL_OR_ZERO_FLOAT_TWO_DIGITS

      public static final com.google.common.base.Predicate<Float> NULL_OR_ZERO_FLOAT_TWO_DIGITS
    • NULL_OR_ZERO_FLOAT_THREE_DIGITS

      public static final com.google.common.base.Predicate<Float> NULL_OR_ZERO_FLOAT_THREE_DIGITS
    • NULL_OR_ZERO_FLOAT_FOUR_DIGITS

      public static final com.google.common.base.Predicate<Float> NULL_OR_ZERO_FLOAT_FOUR_DIGITS
    • NULL_OR_ZERO_FLOAT_FIVE_DIGITS

      public static final com.google.common.base.Predicate<Float> NULL_OR_ZERO_FLOAT_FIVE_DIGITS
    • mc1Digit

      protected static final MathContext mc1Digit
    • mc2Digits

      protected static final MathContext mc2Digits
    • mc3Digits

      protected static final MathContext mc3Digits
    • mc4Digits

      protected static final MathContext mc4Digits
    • mc5Digits

      protected static final MathContext mc5Digits
  • Constructor Details

    • NumberUtil

      public NumberUtil()
  • Method Details

    • divideAndEnsureSum

      public static int[] divideAndEnsureSum(int divisor, int dividend)
      Divide the divisor by the dividend. Returns an array containing the quotients rounded up or down to ensure the sum of the quotients equals the divisor.

      e.g. divideAndEnsureSum(100, 3) returns {34, 33, 33}

      Parameters:
      divisor - the divisor
      dividend - the dividend
      Returns:
      an array whose length equals dividend
    • roundOneDigit

      public static Float roundOneDigit(Float number)
    • roundTwoDigits

      public static Float roundTwoDigits(Float number)
    • roundThreeDigits

      public static Float roundThreeDigits(Float number)
    • roundFourDigits

      public static Float roundFourDigits(Float number)
    • roundFiveDigits

      public static Float roundFiveDigits(Float number)
    • roundNDigits

      public static Float roundNDigits(Float number, int digits)
    • round

      public static Float round(Float number, MathContext mc)