Class NumberUtil

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

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

    Fields 
    Modifier and Type Field Description
    protected static java.math.MathContext mc1Digit  
    protected static java.math.MathContext mc2Digits  
    protected static java.math.MathContext mc3Digits  
    protected static java.math.MathContext mc4Digits  
    protected static java.math.MathContext mc5Digits  
    static com.google.common.base.Predicate<java.lang.Float> NULL_OR_ZERO_FLOAT_FIVE_DIGITS  
    static com.google.common.base.Predicate<java.lang.Float> NULL_OR_ZERO_FLOAT_FOUR_DIGITS  
    static com.google.common.base.Predicate<java.lang.Float> NULL_OR_ZERO_FLOAT_ONE_DIGIT  
    static com.google.common.base.Predicate<java.lang.Float> NULL_OR_ZERO_FLOAT_THREE_DIGITS  
    static com.google.common.base.Predicate<java.lang.Float> NULL_OR_ZERO_FLOAT_TWO_DIGITS  
    static com.google.common.base.Predicate<java.lang.Integer> NULL_OR_ZERO_INTEGER  
  • Constructor Summary

    Constructors 
    Constructor Description
    NumberUtil()  
  • Method Summary

    Modifier and Type Method Description
    static int[] divideAndEnsureSum​(int divisor, int dividend)
    Divide the divisor by the dividend.
    static java.lang.Float round​(java.lang.Float number, java.math.MathContext mc)  
    static java.lang.Float roundFiveDigits​(java.lang.Float number)  
    static java.lang.Float roundFourDigits​(java.lang.Float number)  
    static java.lang.Float roundNDigits​(java.lang.Float number, int digits)  
    static java.lang.Float roundOneDigit​(java.lang.Float number)  
    static java.lang.Float roundThreeDigits​(java.lang.Float number)  
    static java.lang.Float roundTwoDigits​(java.lang.Float number)  

    Methods inherited from class java.lang.Object

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

    • NULL_OR_ZERO_INTEGER

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

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

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

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

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

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

      protected static final java.math.MathContext mc1Digit
    • mc2Digits

      protected static final java.math.MathContext mc2Digits
    • mc3Digits

      protected static final java.math.MathContext mc3Digits
    • mc4Digits

      protected static final java.math.MathContext mc4Digits
    • mc5Digits

      protected static final java.math.MathContext mc5Digits
  • Constructor Details

  • 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 java.lang.Float roundOneDigit​(java.lang.Float number)
    • roundTwoDigits

      public static java.lang.Float roundTwoDigits​(java.lang.Float number)
    • roundThreeDigits

      public static java.lang.Float roundThreeDigits​(java.lang.Float number)
    • roundFourDigits

      public static java.lang.Float roundFourDigits​(java.lang.Float number)
    • roundFiveDigits

      public static java.lang.Float roundFiveDigits​(java.lang.Float number)
    • roundNDigits

      public static java.lang.Float roundNDigits​(java.lang.Float number, int digits)
    • round

      public static java.lang.Float round​(java.lang.Float number, java.math.MathContext mc)