java.lang.Object
org.omnifaces.el.functions.Numbers
Collection of EL functions for number formatting: o:formatBytes(), o:formatCurrency(),
o:formatNumber(), o:formatNumberDefault(), o:formatPercent(),
o:formatThousands() and o:formatThousandsUnit().
- Since:
- 1.2
- Author:
- Bauke Scholtz
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatBytes(Long bytes) Format the given bytes to nearest 10n in the default pattern of the default locale with IEC binary unit (KiB, MiB, etc) with rounding precision of 1 fraction.static StringformatBytesForLocale(Long bytes, Object locale) Format the given bytes to nearest 10n in the default pattern of the given locale with IEC binary unit (KiB, MiB, etc) with rounding precision of 1 fraction.static StringformatCurrency(Number number, String currencySymbol) Format the given number as currency with the given symbol in the default pattern of the default locale.static StringformatCurrencyForLocale(Number number, String currencySymbol, Object locale) Format the given number as currency with the given symbol in the default pattern of the given locale.static StringformatNumber(Number number, String pattern) Format the given number in the given pattern.static StringformatNumberDefault(Number number) Format the given number in the default pattern of the default locale.static StringformatNumberDefaultForLocale(Number number, Object locale) Format the given number in the default pattern of the given locale.static StringformatPercent(Number number) Format the given number as percentage in the default pattern of the default locale.static StringformatPercentForLocale(Number number, Object locale) Format the given number as percentage in the default pattern of the given locale.static StringformatThousands(Number number) Format the given number to nearest 10n (rounded to thousands) in the default pattern of the default locale, immediately suffixed (without space) with metric unit (k, M, G, T, P or E), rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped.static StringformatThousandsForLocale(Number number, Object locale) Format the given number to nearest 10n (rounded to thousands) in the default pattern of the given locale, immediately suffixed (without space) with metric unit (k, M, G, T, P or E), rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped.static StringformatThousandsUnit(Number number, String unit) Format the given number to nearest 10n (rounded to thousands) in the default pattern of the default locale, suffixed with a space, the metric unit prefix (k, M, G, T, P or E) and the given unit, rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped.static StringformatThousandsUnitForLocale(Number number, String unit, Object locale) Format the given number to nearest 10n (rounded to thousands) in the default pattern of the given locale, suffixed with a space, the metric unit prefix (k, M, G, T, P or E) and the given unit, rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped.
-
Method Details
-
formatBytes
Format the given bytes to nearest 10n in the default pattern of the default locale with IEC binary unit (KiB, MiB, etc) with rounding precision of 1 fraction. For example (with English locale):- 1023 bytes will appear as 1023 B
- 1024 bytes will appear as 1.0 KiB
- 500000 bytes will appear as 488.3 KiB
- 1048576 bytes will appear as 1.0 MiB
Faces.getLocale().- Parameters:
bytes- The bytes to be formatted in the default pattern of the default locale.- Returns:
- The formatted bytes.
-
formatBytesForLocale
Format the given bytes to nearest 10n in the default pattern of the given locale with IEC binary unit (KiB, MiB, etc) with rounding precision of 1 fraction. For example (with English locale):- 1023 bytes will appear as 1023 B
- 1024 bytes will appear as 1.0 KiB
- 500000 bytes will appear as 488.3 KiB
- 1048576 bytes will appear as 1.0 MiB
Localeobject or a string representation.- Parameters:
bytes- The bytes to be formatted in the default pattern of the given locale.locale- The locale to obtain the default pattern from.- Returns:
- The formatted bytes.
- Since:
- 5.0
-
formatCurrency
Format the given number as currency with the given symbol in the default pattern of the default locale. This is useful when you want to format numbers as currency in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertNumber>tag. The format locale will be set to the one as obtained byFaces.getLocale().- Parameters:
number- The number to be formatted as currency in the default pattern of the default locale.currencySymbol- The currency symbol to be used.- Returns:
- The number which is formatted as currency with the given symbol.
- Throws:
NullPointerException- When the currency symbol isnull.
-
formatCurrencyForLocale
Format the given number as currency with the given symbol in the default pattern of the given locale. This is useful when you want to format numbers as currency in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertNumber>tag. The given locale can be aLocaleobject or a string representation.- Parameters:
number- The number to be formatted as currency in the default pattern of the given locale.currencySymbol- The currency symbol to be used.locale- The locale to obtain the default pattern from.- Returns:
- The number which is formatted as currency with the given symbol.
- Throws:
NullPointerException- When the currency symbol isnull.- Since:
- 5.0
-
formatNumber
Format the given number in the given pattern. This is useful when you want to format numbers in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertNumber>tag. The format locale will be set to the one as obtained byFaces.getLocale().- Parameters:
number- The number to be formatted in the given pattern.pattern- The pattern to format the given number in.- Returns:
- The number which is formatted in the given pattern.
- Throws:
NullPointerException- When the pattern isnull.
-
formatNumberDefault
Format the given number in the default pattern of the default locale. This is useful when you want to format numbers in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertNumber>tag. The default locale is the one as obtained byFaces.getLocale().- Parameters:
number- The number to be formatted in the default pattern of the default locale.- Returns:
- The number which is formatted in the default pattern of the default locale.
- Since:
- 1.3
-
formatNumberDefaultForLocale
Format the given number in the default pattern of the given locale. This is useful when you want to format numbers in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertNumber>tag. The given locale can be aLocaleobject or a string representation.- Parameters:
number- The number to be formatted in the default pattern of the given locale.locale- The locale to obtain the default pattern from.- Returns:
- The number which is formatted in the default pattern of the given locale.
- Since:
- 2.3
-
formatPercent
Format the given number as percentage in the default pattern of the default locale. This is useful when you want to format numbers as percentage in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertNumber>tag. The default locale is the one as obtained byFaces.getLocale().- Parameters:
number- The number to be formatted as percentage in the default pattern of the default locale.- Returns:
- The number which is formatted as percentage.
- Since:
- 1.6
-
formatPercentForLocale
Format the given number as percentage in the default pattern of the given locale. This is useful when you want to format numbers as percentage in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertNumber>tag. The given locale can be aLocaleobject or a string representation.- Parameters:
number- The number to be formatted as percentage in the default pattern of the given locale.locale- The locale to obtain the default pattern from.- Returns:
- The number which is formatted as percentage.
- Since:
- 5.0
-
formatThousands
Format the given number to nearest 10n (rounded to thousands) in the default pattern of the default locale, immediately suffixed (without space) with metric unit (k, M, G, T, P or E), rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped. For example (with English locale):- 1.6666 will appear as 1.67
- 999.4 will appear as 999
- 999.5 will appear as 1k
- 1004 will appear as 1k
- 1005 will appear as 1.01k
- 1594 will appear as 1.59k
- 1595 will appear as 1.6k
- 9000 will appear as 9k
- 9900 will appear as 9.9k
- 9994 will appear as 9.99k
- 9995 will appear as 10k
- 99990 will appear as 100k
- 9994999 will appear as 9.99M
- 9995000 will appear as 10M
Faces.getLocale(). If the value isnull,NaNor infinity, then this will returnnull.- Parameters:
number- The number to be formatted in the default pattern of the default locale.- Returns:
- The formatted number.
- Since:
- 2.3
-
formatThousandsForLocale
Format the given number to nearest 10n (rounded to thousands) in the default pattern of the given locale, immediately suffixed (without space) with metric unit (k, M, G, T, P or E), rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped. For example (with English locale):- 1.6666 will appear as 1.67
- 999.4 will appear as 999
- 999.5 will appear as 1k
- 1004 will appear as 1k
- 1005 will appear as 1.01k
- 1594 will appear as 1.59k
- 1595 will appear as 1.6k
- 9000 will appear as 9k
- 9900 will appear as 9.9k
- 9994 will appear as 9.99k
- 9995 will appear as 10k
- 99990 will appear as 100k
- 9994999 will appear as 9.99M
- 9995000 will appear as 10M
Localeobject or a string representation. If the value isnull,NaNor infinity, then this will returnnull.- Parameters:
number- The number to be formatted in the default pattern of the given locale.locale- The locale to obtain the default pattern from.- Returns:
- The formatted number.
- Since:
- 5.0
-
formatThousandsUnit
Format the given number to nearest 10n (rounded to thousands) in the default pattern of the default locale, suffixed with a space, the metric unit prefix (k, M, G, T, P or E) and the given unit, rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped. For example (with English locale and unitB):- 1.6666 will appear as 1.67 B
- 999.4 will appear as 999 B
- 999.5 will appear as 1 kB
- 1004 will appear as 1 kB
- 1005 will appear as 1.01 kB
- 1594 will appear as 1.59 kB
- 1595 will appear as 1.6 kB
- 9000 will appear as 9 kB
- 9900 will appear as 9.9 kB
- 9994 will appear as 9.99 kB
- 9995 will appear as 10 kB
- 99990 will appear as 100 kB
- 9994999 will appear as 9.99 MB
- 9995000 will appear as 10 MB
Faces.getLocale(). If the value isnull,NaNor infinity, then this will returnnull.- Parameters:
number- The number to be formatted in the default pattern of the default locale.unit- The unit used in the format. E.g.Bfor Bytes,Wfor Watt, etc. If the unit isnull, then this method will behave exactly as described informatThousands(Number).- Returns:
- The formatted number with unit.
- Since:
- 2.3
-
formatThousandsUnitForLocale
Format the given number to nearest 10n (rounded to thousands) in the default pattern of the given locale, suffixed with a space, the metric unit prefix (k, M, G, T, P or E) and the given unit, rounding half up with a precision of 3 digits, whereafter trailing zeroes in fraction part are stripped. For example (with English locale and unitB):- 1.6666 will appear as 1.67 B
- 999.4 will appear as 999 B
- 999.5 will appear as 1 kB
- 1004 will appear as 1 kB
- 1005 will appear as 1.01 kB
- 1594 will appear as 1.59 kB
- 1595 will appear as 1.6 kB
- 9000 will appear as 9 kB
- 9900 will appear as 9.9 kB
- 9994 will appear as 9.99 kB
- 9995 will appear as 10 kB
- 99990 will appear as 100 kB
- 9994999 will appear as 9.99 MB
- 9995000 will appear as 10 MB
Localeobject or a string representation. If the value isnull,NaNor infinity, then this will returnnull.- Parameters:
number- The number to be formatted in the default pattern of the given locale.unit- The unit used in the format. E.g.Bfor Bytes,Wfor Watt, etc. If the unitlocale- The locale to obtain the default pattern from. isnull, then this method will behave exactly as described informatThousands(Number).- Returns:
- The formatted number with unit.
- Since:
- 5.0
-