Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

[OmniFaces utilities (2.3)] Format the given number to nearest 10^n, suffixed with a space, the metric unit prefix and the given unit


[OmniFaces utilities] The formatThousandsUnit() formats 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. The format locale will be set to the one as obtained by Faces#getLocale(). If the value is null, NaN or infinity, then this will return null.The given unit used in the format is of type B for Bytes, W for Watt, etc. If the unit is null, then this method will behave exactly as described in #formatThousands(Number).

Function
See also: Faces#getLocale() | of:formatThousands()
Usage:

// 1.1 FOO
#{of:formatThousandsUnit(1.1, "FOO")}

// 11.1 FOO
#{of:formatThousandsUnit(11.1, "FOO")}

// 111.1 FOO
#{of:formatThousandsUnit(111.1, "FOO")}

#{of:formatThousandsUnit(1111.1, "FOO")}

// 11.1 kFOO
#{of:formatThousandsUnit(11111.1, "FOO")}

// 111 kFOO
#{of:formatThousandsUnit(111111.1, "FOO")}

// 1.11 MFOO
#{of:formatThousandsUnit(1111111.1, "FOO")}

// 11.1 MFOO
#{of:formatThousandsUnit(11111111.1, "FOO")}

// 111 MFOO
#{of:formatThousandsUnit(111111111.1, "FOO")}

// 1.11 GFOO
#{of:formatThousandsUnit(1111111111.1, "FOO")}

// 11.1 GFOO
#{of:formatThousandsUnit(11111111111.1, "FOO")}

// 111 GFOO
#{of:formatThousandsUnit(111111111111.1, "FOO")}

// 1.11 TFOO
#{of:formatThousandsUnit(1111111111111.1, "FOO")}

// 11.1 TFOO
#{of:formatThousandsUnit(11111111111111.1, "FOO")}

// 111 TFOO
#{of:formatThousandsUnit(111111111111111.1, "FOO")}

// 1.11 PFOO
#{of:formatThousandsUnit(1111111111111111.1, "FOO")}

// 11.1 PFOO
#{of:formatThousandsUnit(11111111111111111.1, "FOO")}

// 111 PFOO
#{of:formatThousandsUnit(111111111111111111.1, "FOO")}

// 1.11 EFOO
#{of:formatThousandsUnit(1111111111111111111.1, "FOO")}

// 1.111111111111111E19 FOO
#{of:formatThousandsUnit(11111111111111111111.1, "FOO")}

// java.util.UnknownFormatConversionException
#{of:formatThousandsUnit(111111111111111111111.1, "FOO")}

API GH


This post first appeared on OmniFaces & JSF Fans, please read the originial post: here

Share the post

[OmniFaces utilities (2.3)] Format the given number to nearest 10^n, suffixed with a space, the metric unit prefix and the given unit

×

Subscribe to Omnifaces & Jsf Fans

Get updates delivered right to your inbox!

Thank you for your subscription

×