Class NumberUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
clamp
(int number, int min, int max) Returns a clamped number between a min and max.static String
Return the parameter number formatted according to the parameterFormatString
.static String
Return the parameter number formatted according to the parameterFormatString
.static String
Return the parameter number formatted according to the parameterFormatString
.static String
Return the parameter number formatted according to the parameterFormatString
.static String
Return the parameter number formatted according to the parameterFormatString
.static String
Return the parameter number formatted according to the parameterFormatString
.static String
The currency symbol to use when formatting numbersstatic String
The decimal symbol to use when formatting numbersstatic int
The grouping-format for numbersstatic String
The grouping symbol, or thousands separator, to use when formatting numbersstatic int
The format to use when formatting negative numbers.static String
The negative symbol to use when formatting numbersstatic Boolean
isBetween
(int number) Returns true if the number parameter falls between the 'first' and 'second' parameters.static Boolean
isBetween
(int number, int first) static Boolean
isBetween
(int number, int first, int second) static Boolean
isBetween
(int number, int first, int second, int inclusive) Returns true if the number parameter falls between the 'first' and 'second' parameters.static void
setCurrencySymbol
(String currencySymbol) The currency symbol to use when formatting numbersstatic void
setDecimalSymbol
(String decimalSymbol) The decimal symbol to use when formatting numbersstatic void
setGroupingFormat
(int groupingFormat) The grouping-format for numbersstatic void
setGroupingSymbol
(String groupingSymbol) The grouping symbol, or thousands separator, to use when formatting numbersstatic void
setNegativeFormat
(int negativeFormat) The format to use when formatting negative numbers.static void
setNegativeSymbol
(String negativeSymbol) The negative symbol to use when formatting numbers
-
Constructor Details
-
NumberUtil
public NumberUtil()
-
-
Method Details
-
setCurrencySymbol
The currency symbol to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Parameters:
currencySymbol
- new currencySymbol. Default value is "$".
-
getCurrencySymbol
The currency symbol to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Returns:
- current value of currencySymbol
-
setDecimalSymbol
The decimal symbol to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Parameters:
decimalSymbol
- new decimalSymbol. Default value is ".".
-
getDecimalSymbol
The decimal symbol to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Returns:
- current value of decimalSymbol
-
setGroupingFormat
public static void setGroupingFormat(int groupingFormat) The grouping-format for numbersNote: the correct format is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Parameters:
groupingFormat
- new groupingFormat. Default value is 1.
-
getGroupingFormat
public static int getGroupingFormat()The grouping-format for numbersNote: the correct format is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Returns:
- current value of groupingFormat
-
setGroupingSymbol
The grouping symbol, or thousands separator, to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Parameters:
groupingSymbol
- new groupingSymbol. Default value is ",".
-
getGroupingSymbol
The grouping symbol, or thousands separator, to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Returns:
- current value of groupingSymbol
-
setNegativeFormat
public static void setNegativeFormat(int negativeFormat) The format to use when formatting negative numbers. Supported values are: 1 = before, 2 = after, 3 = beforeSpace, 4 = afterSpace, 5 = parensNote: the correct format is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Parameters:
negativeFormat
- new negativeFormat. Default value is 1.
-
getNegativeFormat
public static int getNegativeFormat()The format to use when formatting negative numbers. Supported values are: 1 = before, 2 = after, 3 = beforeSpace, 4 = afterSpace, 5 = parensNote: the correct format is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Returns:
- current value of negativeFormat
-
setNegativeSymbol
The negative symbol to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Parameters:
negativeSymbol
- new negativeSymbol. Default value is "-".
-
getNegativeSymbol
The negative symbol to use when formatting numbersNote: the correct symbol is normally auto-derived from GWT's locale system, so the only valid reason to set it is desiring to use a language from one locale in combination with formatting rules from another locale, in a single application and for a single end user.
- Returns:
- current value of negativeSymbol
-
clamp
public static int clamp(int number, int min, int max) Returns a clamped number between a min and max.int clamped = NumberUtil.clamp(10, 0, 5); // Returns 5 because 10 is greater than 5 int clamped = NumberUtil.clamp(-3, 0, 5); // Returns 0 because -3 is less than 0 int clamped = NumberUtil.clamp(4, 0, 5); // Returns 4 because 4 is between 0 and 5
- Parameters:
number
- the number to clampmin
- the number to return if the number is lower than minmax
- the number to return if the number is higher than max- Returns:
- the clamped number
-
isBetween
Returns true if the number parameter falls between the 'first' and 'second' parameters.- Parameters:
number
- Number object to be evaluated- Returns:
- True if the given
number
falls inside the given range, false otherwise @example n = 3; bool = n.isBetween(3, 3, 6, true); // true
-
isBetween
- See Also:
-
isBetween
- See Also:
-
isBetween
Returns true if the number parameter falls between the 'first' and 'second' parameters.- Parameters:
number
- Number object to be evaluatedfirst
- Number at the lower boundarysecond
- Number at the upper boundaryinclusive
- Whether or not the numbers at either end of the boundary should be included in the comparison- Returns:
- True if the given
number
falls inside the given range, false otherwise @example n = 3; bool = n.isBetween(3, 3, 6, true); // true
-
format
Return the parameter number formatted according to the parameterFormatString
. This method is used to implement theformat
functionality, but it can also be used to format arbitrary numbers programmatically.- Parameters:
number
- The number to formatformat
- The format to apply. SeeFormatString
- Returns:
- formatted number string
-
format
Return the parameter number formatted according to the parameterFormatString
. This method is used to implement theformat
functionality, but it can also be used to format arbitrary numbers programmatically.- Parameters:
number
- The number to formatformat
- The format to apply. SeeFormatString
- Returns:
- formatted number string
-
format
Return the parameter number formatted according to the parameterFormatString
. This method is used to implement theformat
functionality, but it can also be used to format arbitrary numbers programmatically.- Parameters:
number
- The number to formatformat
- The format to apply. SeeFormatString
- Returns:
- formatted number string
-
format
Return the parameter number formatted according to the parameterFormatString
. This method is used to implement theformat
functionality, but it can also be used to format arbitrary numbers programmatically.- Parameters:
number
- The number to formatformat
- The format to apply. SeeFormatString
- Returns:
- formatted number string
-
format
Return the parameter number formatted according to the parameterFormatString
. This method is used to implement theformat
functionality, but it can also be used to format arbitrary numbers programmatically.- Parameters:
number
- The number to formatformat
- The format to apply. SeeFormatString
- Returns:
- formatted number string
-
format
Return the parameter number formatted according to the parameterFormatString
. This method is used to implement theformat
functionality, but it can also be used to format arbitrary numbers programmatically.- Parameters:
number
- The number to formatformat
- The format to apply. SeeFormatString
- Returns:
- formatted number string
-