Class NumberUtil

java.lang.Object
com.smartgwt.client.util.NumberUtil

public class NumberUtil extends Object
Static singleton class containing APIs for interacting with Numbers.
  • Constructor Details

    • NumberUtil

      public NumberUtil()
  • Method Details

    • setCurrencySymbol

      public static void setCurrencySymbol(String currencySymbol)
      The currency symbol to use when formatting numbers

      Note: 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

      public static String getCurrencySymbol()
      The currency symbol to use when formatting numbers

      Note: 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

      public static void setDecimalSymbol(String decimalSymbol)
      The decimal symbol to use when formatting numbers

      Note: 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

      public static String getDecimalSymbol()
      The decimal symbol to use when formatting numbers

      Note: 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 numbers

      Note: 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 numbers

      Note: 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

      public static void setGroupingSymbol(String groupingSymbol)
      The grouping symbol, or thousands separator, to use when formatting numbers

      Note: 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

      public static String getGroupingSymbol()
      The grouping symbol, or thousands separator, to use when formatting numbers

      Note: 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 = parens

      Note: 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 = parens

      Note: 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

      public static void setNegativeSymbol(String negativeSymbol)
      The negative symbol to use when formatting numbers

      Note: 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

      public static String getNegativeSymbol()
      The negative symbol to use when formatting numbers

      Note: 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 clamp
      min - the number to return if the number is lower than min
      max - the number to return if the number is higher than max
      Returns:
      the clamped number
    • isBetween

      public static Boolean isBetween(int number)
      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

      public static Boolean isBetween(int number, int first)
      See Also:
    • isBetween

      public static Boolean isBetween(int number, int first, int second)
      See Also:
    • isBetween

      public static Boolean isBetween(int number, int first, int second, int inclusive)
      Returns true if the number parameter falls between the 'first' and 'second' parameters.
      Parameters:
      number - Number object to be evaluated
      first - Number at the lower boundary
      second - Number at the upper boundary
      inclusive - 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

      public static String format(int number, String format)
      Return the parameter number formatted according to the parameter FormatString. This method is used to implement the format functionality, but it can also be used to format arbitrary numbers programmatically.
      Parameters:
      number - The number to format
      format - The format to apply. See FormatString
      Returns:
      formatted number string
    • format

      public static String format(float number, String format)
      Return the parameter number formatted according to the parameter FormatString. This method is used to implement the format functionality, but it can also be used to format arbitrary numbers programmatically.
      Parameters:
      number - The number to format
      format - The format to apply. See FormatString
      Returns:
      formatted number string
    • format

      public static String format(double number, String format)
      Return the parameter number formatted according to the parameter FormatString. This method is used to implement the format functionality, but it can also be used to format arbitrary numbers programmatically.
      Parameters:
      number - The number to format
      format - The format to apply. See FormatString
      Returns:
      formatted number string
    • format

      public static String format(Integer number, String format)
      Return the parameter number formatted according to the parameter FormatString. This method is used to implement the format functionality, but it can also be used to format arbitrary numbers programmatically.
      Parameters:
      number - The number to format
      format - The format to apply. See FormatString
      Returns:
      formatted number string
    • format

      public static String format(Float number, String format)
      Return the parameter number formatted according to the parameter FormatString. This method is used to implement the format functionality, but it can also be used to format arbitrary numbers programmatically.
      Parameters:
      number - The number to format
      format - The format to apply. See FormatString
      Returns:
      formatted number string
    • format

      public static String format(Double number, String format)
      Return the parameter number formatted according to the parameter FormatString. This method is used to implement the format functionality, but it can also be used to format arbitrary numbers programmatically.
      Parameters:
      number - The number to format
      format - The format to apply. See FormatString
      Returns:
      formatted number string