com.bristle.javalib.util
Class MathUtil
java.lang.Object
com.bristle.javalib.util.MathUtil
public class MathUtil
- extends Object
This class contains utility math routines.
Usage:
- Typical scenarios for using this class are:
- Get a random int between 100 and 200 (inclusive).
int intRandom = MathUtil.getRandomInt(100, 200);
- See the source code of the inner Tester class for more examples.
Assumptions:
Effects:
- None.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
$Log$
|
Nested Class Summary |
static class |
MathUtil.Tester
Each class contains a Tester inner class with a main() for easier
unit testing. |
|
Method Summary |
static int |
getRandomInt(int intMin,
int intMax)
Return a random int between the specified min and max (inclusive). |
static String |
trimFloat(double dblVal,
int intMaxDecimalDigits)
Round the specified number to the specified number of decimal digits
(digits following the decimal point) and then trim any trailing zeros,
returning a string containing the specified value with perhaps less
precision. |
MathUtil
public MathUtil()
getRandomInt
public static int getRandomInt(int intMin,
int intMax)
- Return a random int between the specified min and max (inclusive).
- Parameters:
intMin - Min value.intMax - Max value.
- Returns:
- Random int.
trimFloat
public static String trimFloat(double dblVal,
int intMaxDecimalDigits)
- Round the specified number to the specified number of decimal digits
(digits following the decimal point) and then trim any trailing zeros,
returning a string containing the specified value with perhaps less
precision.
- Parameters:
dblVal - Number to trimintMaxDecimalDigits - Max number of non-zero decimal digits to
preserve.