Class NumberHelper
java.lang.Object
org.sentrysoftware.metricshub.engine.common.helpers.NumberHelper
Helper class for number-related operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternPattern to detect integers with trailing zeros. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcleanUpEnumInput(String state) Removes the fractional part and the decimal point of the given state if the fractional part contains only 0 after the decimal point.static StringFormat the given value as Stringstatic StringformatNumber(Number n, @NonNull String format) Format the given value as Stringstatic DoubleparseDouble(String value, Double defaultValue) Parse the given double value, if the parsing fails return the default valuestatic IntegerParse the given integer value, if the parsing fails return the default valuestatic doubleround(double value, int places, RoundingMode roundingMode) Round the given double value using the specified decimal places
-
Field Details
-
INTEGER_DETECT_PATTERN
Pattern to detect integers with trailing zeros.
-
-
Method Details
-
parseDouble
Parse the given double value, if the parsing fails return the default value- Parameters:
value- The value we wish to parsedefaultValue- The default value to return if the parsing fails- Returns:
Doublevalue
-
parseInt
Parse the given integer value, if the parsing fails return the default value- Parameters:
value- The value we wish to parsedefaultValue- The default value to return if the parsing fails- Returns:
Integervalue
-
round
Round the given double value using the specified decimal places- Parameters:
value- The value we wish to roundplaces- The required decimal places expected as positiveroundingMode- The rounding behavior used by theBigDecimalobject for the numerical operations- Returns:
- double value
-
cleanUpEnumInput
Removes the fractional part and the decimal point of the given state if the fractional part contains only 0 after the decimal point. The state is trimmed and converted to lower case- Parameters:
state- the value we wish to process- Returns:
- String value
-
formatNumber
Format the given value as String- Parameters:
n- numeric value to formatformat- string format used to format decimal parts- Returns:
Stringvalue
-
formatNumber
Format the given value as String- Parameters:
n- numeric value to format- Returns:
Stringvalue
-