|
ProgramixGenericLib v5.0.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.programix.math.DecimalTools
public class DecimalTools
Method Summary | |
---|---|
static BigDecimal |
convert(int value)
Converts the specified value to a BigDecimal returning one of the shared, common, immutable instances if possible. |
static BigDecimal |
convert(long value)
Converts the specified value to a BigDecimal returning one of the shared, common, immutable instances if possible. |
static BigDecimal |
convert(Number value)
Converts the specified value to a BigDecimal returning one of the shared, common, immutable instances if possible. |
static boolean |
equalTo(BigDecimal a,
BigDecimal b)
Returns true if a is numerically equal to b (with no regard to scale). |
static String |
format(BigDecimal value,
int integerDigitCount,
char integerPaddingChar,
int fractionalDigitCount,
char fractionalPaddingChar,
char thousandGroupingChar)
|
static String |
format(BigDecimal value,
int integerDigitCount,
int fractionalDigitCount)
|
static BigDecimal |
getMaxValueFor(int integerDigitCount,
int fractionalDigitCount)
Returns the largest positive value than can fit into the specified number of integer and fractional digits (all nines). |
static BigDecimal |
getMinValueFor(int integerDigitCount,
int fractionalDigitCount)
Returns the most negative value than can fit into the specified number of integer and fractional digits (all nines preceded by a minus sign). |
static boolean |
greaterThan(BigDecimal a,
BigDecimal b)
Returns true if a is numerically greater than b (with no regard to scale). |
static boolean |
greaterThanOrEqualTo(BigDecimal a,
BigDecimal b)
Returns true if a is numerically greater than or equal to b (with no regard to scale). |
static boolean |
isDifferent(BigDecimal a,
BigDecimal b)
Compares two BigDecimals to see if they are "different" (without regard to the scales of each one). |
static boolean |
isEmpty(BigDecimal val)
Returns true if the specified BigDecimal is either null or zero. |
static boolean |
isNegative(BigDecimal val)
Returns true if val is negative (numerically less than ZERO ). |
static boolean |
isNotEmpty(BigDecimal val)
Returns true if the specified BigDecimal is not null and is not equal to zero. |
static boolean |
isNotNegative(BigDecimal val)
Returns true if val is non-negative (numerically greater than or equal to ZERO ). |
static boolean |
isNotPositive(BigDecimal val)
Returns true if val is non-positive (numerically less than or equal to ZERO ). |
static boolean |
isNotZero(BigDecimal val)
Returns true if val is numerically not equal to ZERO (with no regard to scale). |
static boolean |
isPositive(BigDecimal val)
Returns true if val is positive (numerically greater than ZERO ). |
static boolean |
isSame(BigDecimal a,
BigDecimal b)
Compares two BigDecimals to see if they are the "same" (without regard to the scales of each one). |
static boolean |
isZero(BigDecimal val)
Returns true if val is numerically equal to ZERO (with no regard to scale). |
static boolean |
lessThan(BigDecimal a,
BigDecimal b)
Returns true if a is numerically less than b (with no regard to scale). |
static boolean |
lessThanOrEqualTo(BigDecimal a,
BigDecimal b)
Returns true if a is numerically less than or equal to b (with no regard to scale). |
static BigDecimal |
max(BigDecimal a,
BigDecimal b)
Returns the numerically larger of a and b (with no regard to scale). |
static BigDecimal |
max(BigDecimal a,
BigDecimal b,
BigDecimal c)
Returns the numerically largest of a, b and c (with no regard to scale). |
static BigDecimal |
min(BigDecimal a,
BigDecimal b)
Returns the numerically smaller of a and b (with no regard to scale). |
static BigDecimal |
min(BigDecimal a,
BigDecimal b,
BigDecimal c)
Returns the numerically smallest of a, b and c (with no regard to scale). |
static boolean |
notEqualTo(BigDecimal a,
BigDecimal b)
Returns true if a is numerically not equal to b (with no regard to scale). |
static boolean |
notGreaterThan(BigDecimal a,
BigDecimal b)
Returns true if a is numerically not greater than b (with no regard to scale). |
static boolean |
notLessThan(BigDecimal a,
BigDecimal b)
Returns true if a is numerically not less than b (with no regard to scale). |
static BigDecimal |
parseBigDecimal(String source)
Permissively parses the passed String into a BigDecimal . |
static BigDecimal |
parseBigDecimal(String source,
BigDecimal defaultValue)
Permissively parses the passed String into a BigDecimal . |
static double |
parseDouble(String source)
Permissively parses the passed String into a double. |
static double |
parseDouble(String source,
double defaultValue)
Permissively parses the passed String into a double. |
static Value |
parseValue(String source)
Permissively parses the passed String into a Value
that if not empty, wraps an instance of BigDecimal . |
static BigDecimal |
rangeBound(BigDecimal minValue,
BigDecimal value,
BigDecimal maxValue)
Bounds value to the specified range. |
static BigDecimal |
round(BigDecimal value)
Rounds to the nearest 1 (nearest integer). |
static BigDecimal |
round(BigDecimal value,
BigDecimal nearest)
Equivalent to: round(value, nearest, BigDecimal.ROUND_HALF_UP) |
static BigDecimal |
round(BigDecimal value,
BigDecimal nearest,
int roundingMode)
Returns value rounded to the nearest multiple of the specified value nearest. |
static BigDecimal |
roundDollar(BigDecimal value)
Same as round(BigDecimal) (nearest integer). |
static BigDecimal |
roundEighth(BigDecimal value)
Rounds to the nearest 1/8 (multiple of 0.125). |
static BigDecimal |
roundHalf(BigDecimal value)
Rounds to the nearest 1/2 (multiple of 0.5). |
static BigDecimal |
roundHundredth(BigDecimal value)
Rounds to the nearest 0.01. |
static BigDecimal |
roundPenny(BigDecimal value)
Same as roundHundredth(BigDecimal) . |
static BigDecimal |
roundQuarter(BigDecimal value)
Rounds to the nearest 1/4 (multiple of 0.25). |
static BigDecimal |
roundSixteenth(BigDecimal value)
Rounds to the nearest 1/16 (multiple of 0.0625). |
static BigDecimal |
roundTenth(BigDecimal value)
Rounds to the nearest 0.1. |
static BigDecimal |
roundThousandth(BigDecimal value)
Rounds to the nearest 0.001. |
static BigDecimal |
sum(BigDecimal[] val)
Returns the sum of all of the values in the array passed in. |
static BigDecimal[] |
toArray(Collection<BigDecimal> bigDecimals)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final BigDecimal ZERO
public static final BigDecimal ONE
public static final BigDecimal TWO
public static final BigDecimal THREE
public static final BigDecimal FOUR
public static final BigDecimal FIVE
public static final BigDecimal SIX
public static final BigDecimal SEVEN
public static final BigDecimal EIGHT
public static final BigDecimal NINE
public static final BigDecimal TEN
public static final BigDecimal ELEVEN
public static final BigDecimal TWELVE
public static final BigDecimal THIRTEEN
public static final BigDecimal FOURTEEN
public static final BigDecimal FIFTEEN
public static final BigDecimal SIXTEEN
public static final BigDecimal SEVENTEEN
public static final BigDecimal EIGHTEEN
public static final BigDecimal NINETEEN
public static final BigDecimal TWENTY
public static final BigDecimal TWENTY_ONE
public static final BigDecimal TWENTY_TWO
public static final BigDecimal TWENTY_THREE
public static final BigDecimal TWENTY_FOUR
public static final BigDecimal TWENTY_FIVE
public static final BigDecimal TWENTY_SIX
public static final BigDecimal TWENTY_SEVEN
public static final BigDecimal TWENTY_EIGHT
public static final BigDecimal TWENTY_NINE
public static final BigDecimal THIRTY
public static final BigDecimal THIRTY_ONE
public static final BigDecimal THIRTY_TWO
public static final BigDecimal THIRTY_THREE
public static final BigDecimal THIRTY_FOUR
public static final BigDecimal THIRTY_FIVE
public static final BigDecimal THIRTY_SIX
public static final BigDecimal THIRTY_SEVEN
public static final BigDecimal THIRTY_EIGHT
public static final BigDecimal THIRTY_NINE
public static final BigDecimal FORTY
public static final BigDecimal FORTY_ONE
public static final BigDecimal FORTY_TWO
public static final BigDecimal FORTY_THREE
public static final BigDecimal FORTY_FOUR
public static final BigDecimal FORTY_FIVE
public static final BigDecimal FORTY_SIX
public static final BigDecimal FORTY_SEVEN
public static final BigDecimal FORTY_EIGHT
public static final BigDecimal FORTY_NINE
public static final BigDecimal FIFTY
public static final BigDecimal FIFTY_ONE
public static final BigDecimal FIFTY_TWO
public static final BigDecimal FIFTY_THREE
public static final BigDecimal FIFTY_FOUR
public static final BigDecimal FIFTY_FIVE
public static final BigDecimal FIFTY_SIX
public static final BigDecimal FIFTY_SEVEN
public static final BigDecimal FIFTY_EIGHT
public static final BigDecimal FIFTY_NINE
public static final BigDecimal SIXTY
public static final BigDecimal SIXTY_ONE
public static final BigDecimal SIXTY_TWO
public static final BigDecimal SIXTY_THREE
public static final BigDecimal SIXTY_FOUR
public static final BigDecimal SIXTY_FIVE
public static final BigDecimal SIXTY_SIX
public static final BigDecimal SIXTY_SEVEN
public static final BigDecimal SIXTY_EIGHT
public static final BigDecimal SIXTY_NINE
public static final BigDecimal SEVENTY
public static final BigDecimal SEVENTY_ONE
public static final BigDecimal SEVENTY_TWO
public static final BigDecimal SEVENTY_THREE
public static final BigDecimal SEVENTY_FOUR
public static final BigDecimal SEVENTY_FIVE
public static final BigDecimal SEVENTY_SIX
public static final BigDecimal SEVENTY_SEVEN
public static final BigDecimal SEVENTY_EIGHT
public static final BigDecimal SEVENTY_NINE
public static final BigDecimal EIGHTY
public static final BigDecimal EIGHTY_ONE
public static final BigDecimal EIGHTY_TWO
public static final BigDecimal EIGHTY_THREE
public static final BigDecimal EIGHTY_FOUR
public static final BigDecimal EIGHTY_FIVE
public static final BigDecimal EIGHTY_SIX
public static final BigDecimal EIGHTY_SEVEN
public static final BigDecimal EIGHTY_EIGHT
public static final BigDecimal EIGHTY_NINE
public static final BigDecimal NINETY
public static final BigDecimal NINETY_ONE
public static final BigDecimal NINETY_TWO
public static final BigDecimal NINETY_THREE
public static final BigDecimal NINETY_FOUR
public static final BigDecimal NINETY_FIVE
public static final BigDecimal NINETY_SIX
public static final BigDecimal NINETY_SEVEN
public static final BigDecimal NINETY_EIGHT
public static final BigDecimal NINETY_NINE
public static final BigDecimal ONE_HUNDRED
public static final BigDecimal ONE_THOUSAND
public static final BigDecimal TEN_THOUSAND
public static final BigDecimal ONE_HUNDRED_THOUSAND
public static final BigDecimal ONE_MILLION
public static final BigDecimal TEN_MILLION
public static final BigDecimal ONE_HUNDRED_MILLION
public static final BigDecimal ONE_BILLION
public static final BigDecimal TEN_BILLION
public static final BigDecimal ONE_HUNDRED_BILLION
public static final BigDecimal ONE_TRILLION
public static final BigDecimal ONE_HALF
public static final BigDecimal ONE_THIRD
public static final BigDecimal ONE_QUARTER
public static final BigDecimal ONE_FOURTH
ONE_QUARTER
public static final BigDecimal ONE_FIFTH
public static final BigDecimal ONE_SIXTH
public static final BigDecimal ONE_SEVENTH
public static final BigDecimal ONE_EIGHTH
public static final BigDecimal ONE_NINTH
public static final BigDecimal ONE_TENTH
public static final BigDecimal ONE_ELEVENTH
public static final BigDecimal ONE_TWELFTH
public static final BigDecimal ONE_SIXTEENTH
public static final BigDecimal ONE_HUNDREDTH
public static final BigDecimal ONE_THOUSANDTH
public static final BigDecimal ONE_TEN_THOUSANDTH
public static final BigDecimal ONE_MILLIONTH
public static final BigDecimal NEGATIVE_ONE
public static final char GROUPING_CHAR_COMMA
public static final char GROUPING_CHAR_NONE
public static final char PAD_CHAR_SPACE
public static final char PAD_CHAR_ZERO
public static final char PAD_CHAR_NONE
public static final BigDecimal[] ZERO_LEN_ARRAY
Method Detail |
---|
public static boolean isSame(BigDecimal a, BigDecimal b)
compareTo
on
BigDecimal).
Returns true if a is the same as b.
Specifically, they are the same if either of the following are true:
a
- the first number or nullb
- the second number or null
public static boolean isDifferent(BigDecimal a, BigDecimal b)
compareTo
on
BigDecimal).
Returns true if a is different than b.
Specifically, they are different if any of the following are true:
a
- the first number or nullb
- the second number or null
public static boolean equalTo(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static boolean notEqualTo(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static boolean lessThan(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static boolean lessThanOrEqualTo(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static boolean greaterThan(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static boolean greaterThanOrEqualTo(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static boolean notLessThan(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static boolean notGreaterThan(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static BigDecimal max(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static BigDecimal max(BigDecimal a, BigDecimal b, BigDecimal c) throws IllegalArgumentException
IllegalArgumentException
- if either a, b,
or c is null.public static BigDecimal min(BigDecimal a, BigDecimal b) throws IllegalArgumentException
IllegalArgumentException
- if either a or b
is null.public static BigDecimal min(BigDecimal a, BigDecimal b, BigDecimal c) throws IllegalArgumentException
IllegalArgumentException
- if either a, b,
or c is null.public static BigDecimal rangeBound(BigDecimal minValue, BigDecimal value, BigDecimal maxValue) throws IllegalArgumentException
IllegalArgumentException
- if any of minValue,
value, or maxValue is null.public static boolean isZero(BigDecimal val) throws IllegalArgumentException
ZERO
(with no regard to scale).
IllegalArgumentException
- if val is null.public static boolean isNotZero(BigDecimal val) throws IllegalArgumentException
ZERO
(with no regard to scale).
IllegalArgumentException
- if val is null.public static boolean isNegative(BigDecimal val) throws IllegalArgumentException
ZERO
).
IllegalArgumentException
- if val is null.public static boolean isNotNegative(BigDecimal val) throws IllegalArgumentException
ZERO
).
IllegalArgumentException
- if val is null.public static boolean isPositive(BigDecimal val) throws IllegalArgumentException
ZERO
). Note that zero is not considered to be a
positive number.
IllegalArgumentException
- if val is null.public static boolean isNotPositive(BigDecimal val) throws IllegalArgumentException
ZERO
).
Note that zero is not considered to be a positive number.
IllegalArgumentException
- if val is null.public static boolean isEmpty(BigDecimal val)
public static boolean isNotEmpty(BigDecimal val)
public static BigDecimal[] toArray(Collection<BigDecimal> bigDecimals)
public static Value parseValue(String source)
Value
that if not empty, wraps an instance of BigDecimal
.
Parses the passed string by ignoring all characters not in the
set {0, 1, 2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,. , -}. The negative
sign '-' is ignored if it is not the first valid
character; and only the first decimal point '.' is kept, any
additional decimal points are ignored. There is no need to trim any
whitespace before calling this method as none of the whitespace
characters are in the valid set of characters listed above (in fact,
pre-trimming of whitespace is likely to be less efficient than
allowing this method to do the whitespace trimming).
Calling the getBigDecimal()
method
on the returned Value is inexpensive (the reference to
the wrapped BigDecimal created during parsing is simply
returned—no new object is created and no parsing need be done).
If null is passed in, then
ValueFactory.NULL_INSTANCE
is
returned. NULL_INSTANCE always returns true for
isEmpty()
and for
isNull()
; and returns false for
isNumeric()
.
If a zero-length String, a String
containing only whitespace, or a String that contains
no valid characters is passed in, then
ValueFactory.ZERO_LEN_STRING_INSTANCE
is returned.
ZERO_LEN_STRING_INSTANCE always returns true for
isEmpty()
; and returns false for
isNull()
and for
isNumeric()
.
source
- to be parsed
Value
.parseBigDecimal(String)
,
StringTools.winnowDecimal(String)
public static BigDecimal parseBigDecimal(String source) throws ValueException
BigDecimal
.
Parses the passed string by ignoring all characters not in the
set {0, 1, 2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,. , -}. The negative
sign '-' is ignored if it is not the first valid
character; and only the first decimal point '.' is kept, any
additional decimal points are ignored. There is no need to trim any
whitespace before calling this method as none of the whitespace
characters are in the valid set of characters listed above (in fact,
pre-trimming of whitespace is likely to be less efficient than
allowing this method to do the whitespace trimming).
If null, a zero-length String, a String
containing only whitespace, or a String that contains
no valid characters is passed in, then
a ValueException
is thrown.
source
- to be parsed
ValueException
- if the parsing fails. ValueException
is a RuntimeException
and is not required to be caught.parseBigDecimal(String, BigDecimal)
,
parseValue(String)
,
StringTools.winnowDecimal(String)
public static BigDecimal parseBigDecimal(String source, BigDecimal defaultValue)
BigDecimal
.
Parses the passed string by ignoring all characters not in the
set {0, 1, 2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,. , -}. The negative
sign '-' is ignored if it is not the first valid
character; and only the first decimal point '.' is kept, any
additional decimal points are ignored. There is no need to trim any
whitespace before calling this method as none of the whitespace
characters are in the valid set of characters listed above (in fact,
pre-trimming of whitespace is likely to be less efficient than
allowing this method to do the whitespace trimming).
If null, a zero-length String, a String containing only whitespace, or a String that contains no valid characters is passed in, then the specified defaultValue is returned.
source
- to be parseddefaultValue
- the value to return if parsing does not find
any valid characters.
parseBigDecimal(String)
,
StringTools.winnowDecimal(String)
public static double parseDouble(String source) throws ValueException
If null, a zero-length String, a String
containing only whitespace, or a String that contains
no valid characters is passed in, then
a ValueException
is thrown.
source
- to be parsed
ValueException
- if the parsing fails. ValueException
is a RuntimeException
and is not required to be caught.parseDouble(String, double)
,
parseValue(String)
,
StringTools.winnowDecimal(String)
public static double parseDouble(String source, double defaultValue)
If null, a zero-length String, a String containing only whitespace, or a String that contains no valid characters is passed in, then the specified defaultValue is returned.
source
- to be parseddefaultValue
- the value to return if parsing does not find
any valid characters.
parseDouble(String)
,
StringTools.winnowDecimal(String)
public static BigDecimal convert(int value)
public static BigDecimal convert(long value)
public static BigDecimal convert(Number value)
public static BigDecimal round(BigDecimal value, BigDecimal nearest, int roundingMode)
BigDecimal
).
public static BigDecimal round(BigDecimal value, BigDecimal nearest)
public static BigDecimal round(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundTenth(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundHundredth(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundThousandth(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundSixteenth(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundEighth(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundQuarter(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundHalf(BigDecimal value)
BigDecimal.ROUND_HALF_UP
is used.
public static BigDecimal roundPenny(BigDecimal value)
roundHundredth(BigDecimal)
. This method exists to
enhance readability when US currency is being used.
public static BigDecimal roundDollar(BigDecimal value)
round(BigDecimal)
(nearest integer).
This method exists to enhance readability when US currency is being used.
public static BigDecimal sum(BigDecimal[] val)
val
- values to total up.
NumberTools.sum(int[])
,
NumberTools.sum(double[])
public static BigDecimal getMaxValueFor(int integerDigitCount, int fractionalDigitCount)
integerDigitCount
- the number of digits to the left of the decimal
decimal point.fractionalDigitCount
- the number of digits to the right of the
decimal point.
public static BigDecimal getMinValueFor(int integerDigitCount, int fractionalDigitCount)
integerDigitCount
- the number of digits to the left of the decimal
decimal point.fractionalDigitCount
- the number of digits to the right of the
decimal point.
public static String format(BigDecimal value, int integerDigitCount, char integerPaddingChar, int fractionalDigitCount, char fractionalPaddingChar, char thousandGroupingChar)
public static String format(BigDecimal value, int integerDigitCount, int fractionalDigitCount)
|
ProgramixGenericLib v5.0.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |