Package org.nuiton.util
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.MathContextmc1Digitprotected static java.math.MathContextmc2Digitsprotected static java.math.MathContextmc3Digitsprotected static java.math.MathContextmc4Digitsprotected static java.math.MathContextmc5Digitsstatic com.google.common.base.Predicate<java.lang.Float>NULL_OR_ZERO_FLOAT_FIVE_DIGITSstatic com.google.common.base.Predicate<java.lang.Float>NULL_OR_ZERO_FLOAT_FOUR_DIGITSstatic com.google.common.base.Predicate<java.lang.Float>NULL_OR_ZERO_FLOAT_ONE_DIGITstatic com.google.common.base.Predicate<java.lang.Float>NULL_OR_ZERO_FLOAT_THREE_DIGITSstatic com.google.common.base.Predicate<java.lang.Float>NULL_OR_ZERO_FLOAT_TWO_DIGITSstatic 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.Floatround(java.lang.Float number, java.math.MathContext mc)static java.lang.FloatroundFiveDigits(java.lang.Float number)static java.lang.FloatroundFourDigits(java.lang.Float number)static java.lang.FloatroundNDigits(java.lang.Float number, int digits)static java.lang.FloatroundOneDigit(java.lang.Float number)static java.lang.FloatroundThreeDigits(java.lang.Float number)static java.lang.FloatroundTwoDigits(java.lang.Float number)
-
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
-
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 divisordividend- 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)
-