Class Numbers


  • public class Numbers
    extends Object
    Created by tchemit on 29/12/2017.
    Author:
    Tony Chemit - dev@tchemit.fr
    • Field Detail

      • NULL_OR_ZERO_INTEGER

        public static final Predicate<Integer> NULL_OR_ZERO_INTEGER
      • NULL_OR_ZERO_FLOAT_ONE_DIGIT

        public static final Predicate<Float> NULL_OR_ZERO_FLOAT_ONE_DIGIT
      • NULL_OR_ZERO_FLOAT_TWO_DIGITS

        public static final Predicate<Float> NULL_OR_ZERO_FLOAT_TWO_DIGITS
      • NULL_OR_ZERO_FLOAT_THREE_DIGITS

        public static final Predicate<Float> NULL_OR_ZERO_FLOAT_THREE_DIGITS
      • NULL_OR_ZERO_FLOAT_FOUR_DIGITS

        public static final Predicate<Float> NULL_OR_ZERO_FLOAT_FOUR_DIGITS
      • NULL_OR_ZERO_FLOAT_FIVE_DIGITS

        public static final Predicate<Float> NULL_OR_ZERO_FLOAT_FIVE_DIGITS
    • Constructor Detail

      • Numbers

        public Numbers()
    • Method Detail

      • 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)
      • roundNDigits

        public static Float roundNDigits​(Float number,
                                         int digits)