Package org.kissweb
Class NumberUtils
java.lang.Object
org.kissweb.NumberUtils
Author: Blake McBride
 Date: 10/24/20
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleandoubleEqual(double d1, double d2, double maxdiff) Correctly compare two doubles.static booleanIs string a valid number?static voidstatic doubleParse a String into a double.static intParse a String into an int.static longParse a String into a long.static doubleround(double n, int p) Round a number to the nearest p decimal places.static doubleroundDown(double n, int p) Round a number down to the nearest p decimal places.static doubleroundUp(double n, int p) Round a number up to the nearest p decimal places.static doubletrunk(double v) Truncate the decimal part of a number.
- 
Constructor Details- 
NumberUtilspublic NumberUtils()
 
- 
- 
Method Details- 
doubleEqualpublic static boolean doubleEqual(double d1, double d2, double maxdiff) Correctly compare two doubles.- Parameters:
- d1-
- d2-
- maxdiff-
- Returns:
- true if the two doubles are different by less than maxdiff
 
- 
roundpublic static double round(double n, int p) Round a number to the nearest p decimal places.- Parameters:
- n- the number to be rounded
- p- the number of decimal places
- Returns:
- the rounded number
 
- 
roundUppublic static double roundUp(double n, int p) Round a number up to the nearest p decimal places.- Parameters:
- n- the number to be rounded
- p- the number of decimal places
- Returns:
- the rounded number
 
- 
roundDownpublic static double roundDown(double n, int p) Round a number down to the nearest p decimal places.- Parameters:
- n- the number to be rounded
- p- the number of decimal places
- Returns:
- the rounded number
 
- 
trunkpublic static double trunk(double v) Truncate the decimal part of a number.- Parameters:
- v-
- Returns:
 
- 
parseDoubleParse a String into a double.- Parameters:
- s-
- Returns:
 
- 
parseLongParse a String into a long.- Parameters:
- s-
- Returns:
 
- 
isValidNumberIs string a valid number?- Parameters:
- s-
- Returns:
 
- 
parseIntParse a String into an int.- Parameters:
- s-
- Returns:
 
- 
main
 
-