public final class Numbers extends Object
Collection of EL functions for number formatting: of:formatBytes()
, of:formatCurrency()
,
of:formatNumber()
, of:formatNumberDefault()
, of:formatPercent()
,
of:formatThousands()
and of:formatThousandsUnit()
.
Modifier and Type | Method and Description |
---|---|
static String |
formatBytes(Long bytes)
Format the given bytes to nearest 10n with IEC binary unit (KiB, MiB, etc) with rounding precision of
1 fraction.
|
static String |
formatCurrency(Number number,
String currencySymbol)
Format the given number as currency with the given symbol.
|
static String |
formatNumber(Number number,
String pattern)
Format the given number in the given pattern.
|
static String |
formatNumberDefault(Number number)
Format the given number in the default pattern of the default locale.
|
static String |
formatNumberDefaultForLocale(Number number,
Object locale)
Format the given number in the default pattern of the given locale.
|
static String |
formatPercent(Number number)
Format the given number as percentage.
|
static String |
formatThousands(Number number)
Format the given number to nearest 10n (rounded to thousands), 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 String |
formatThousandsUnit(Number number,
String unit)
Format the given number to nearest 10n (rounded to thousands), 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.
|
public static String formatBytes(Long bytes)
Faces.getLocale()
.bytes
- The bytes to be formatted.public static String formatCurrency(Number number, String currencySymbol)
title
attribute of an UI component, or the itemLabel
attribute of select item, or wherever you can't use the <f:convertNumber>
tag. The format
locale will be set to the one as obtained by Faces.getLocale()
.number
- The number to be formatted as currency.currencySymbol
- The currency symbol to be used.NullPointerException
- When the currency symbol is null
.public static String formatNumber(Number number, String pattern)
title
attribute of an UI component, or the itemLabel
attribute of select item, or
wherever you can't use the <f:convertNumber>
tag. The format locale will be set to the one as
obtained by Faces.getLocale()
.number
- The number to be formatted in the given pattern.pattern
- The pattern to format the given number in.NullPointerException
- When the pattern is null
.public static String formatNumberDefault(Number number)
title
attribute of an UI component, or the itemLabel
attribute of select item, or wherever you can't use the <f:convertNumber>
tag. The default
locale is the one as obtained by Faces.getLocale()
.number
- The number to be formatted in the default pattern of the default locale.public static String formatNumberDefaultForLocale(Number number, Object locale)
title
attribute of an UI component, or the itemLabel
attribute of select item, or wherever you can't use the <f:convertNumber>
tag. The given
locale can be a Locale
object or a string representation.number
- The number to be formatted in the default pattern of the given locale.locale
- The locale to obtain the default pattern from.public static String formatPercent(Number number)
title
attribute of an UI component, or the itemLabel
attribute of select item, or wherever you can't use the <f:convertNumber>
tag. The format
locale will be set to the one as obtained by Faces.getLocale()
.number
- The number to be formatted as percentage.public static String formatThousands(Number number)
Faces.getLocale()
.
If the value is null
, NaN
or infinity, then this will return null
.number
- The number to be formatted.public static String formatThousandsUnit(Number number, String unit)
B
):
Faces.getLocale()
.
If the value is null
, NaN
or infinity, then this will return null
.number
- The number to be formatted.unit
- The unit used in the format. E.g. B
for Bytes, W
for Watt, etc. If the unit
is null
, then this method will behave exactly as described in formatThousands(Number)
.Copyright © 2012–2018 OmniFaces. All rights reserved.