Package org.kissweb
Class NumberUtils
java.lang.Object
org.kissweb.NumberUtils
Author: Blake McBride
Date: 10/24/20
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
doubleEqual
(double d1, double d2, double maxdiff) Correctly compare two doubles.static boolean
Is string a valid number?static void
static double
Parse a String into a double.static int
Parse a String into an int.static long
Parse a String into a long.static double
round
(double n, int p) Round a number to the nearest p decimal places.static double
roundDown
(double n, int p) Round a number down to the nearest p decimal places.static double
roundUp
(double n, int p) Round a number up to the nearest p decimal places.static double
trunk
(double v) Truncate the decimal part of a number.
-
Constructor Details
-
NumberUtils
public NumberUtils()
-
-
Method Details
-
doubleEqual
public 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
-
round
public static double round(double n, int p) Round a number to the nearest p decimal places.- Parameters:
n
- the number to be roundedp
- the number of decimal places- Returns:
- the rounded number
-
roundUp
public static double roundUp(double n, int p) Round a number up to the nearest p decimal places.- Parameters:
n
- the number to be roundedp
- the number of decimal places- Returns:
- the rounded number
-
roundDown
public static double roundDown(double n, int p) Round a number down to the nearest p decimal places.- Parameters:
n
- the number to be roundedp
- the number of decimal places- Returns:
- the rounded number
-
trunk
public static double trunk(double v) Truncate the decimal part of a number.- Parameters:
v
-- Returns:
-
parseDouble
Parse a String into a double.- Parameters:
s
-- Returns:
-
parseLong
Parse a String into a long.- Parameters:
s
-- Returns:
-
isValidNumber
Is string a valid number?- Parameters:
s
-- Returns:
-
parseInt
Parse a String into an int.- Parameters:
s
-- Returns:
-
main
-