miercuri, 3 februarie 2016

[OmniFaces utilities (2.3)] Format the given number to nearest 10^n (rounded to thousands)


[OmniFaces utilities] The formatThousands() formats 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. Numbers lower than thousand are not affected. 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.

In OmniFaces 2.4 the incorrectly trimmed trailing zeroes from non-fractional integer numbers was fixed and now also supports cutting down fractions of values lower than thousand.

Function
Usage

// 1.1
#{of:formatThousands(1.1)}

// 11.1
#{of:formatThousands(11.1)}

// 111.1
#{of:formatThousands(111.1)}

// 1.11k
#{of:formatThousands(1111.1)}

// 11.1k
#{of:formatThousands(11111.1)}

// 111k
#{of:formatThousands(111111.1)}

// 1.11M
#{of:formatThousands(1111111.1)}

// 11.1M
#{of:formatThousands(11111111.1)}

// 111M
#{of:formatThousands(111111111.1)}

// 1.11G
#{of:formatThousands(1111111111.1)}

// 11.1G
#{of:formatThousands(11111111111.1)}

// 111G
#{of:formatThousands(111111111111.1)}

// 1.11T
#{of:formatThousands(1111111111111.1)}

// 11.1T
#{of:formatThousands(11111111111111.1)}

// 111T
#{of:formatThousands(111111111111111.1)}

// 1.11P
#{of:formatThousands(1111111111111111.1)}

// 11.1P
#{of:formatThousands(11111111111111111.1)}

// 111P
#{of:formatThousands(111111111111111111.1)}

// 1.11E
#{of:formatThousands(1111111111111111111.1)}

// 1.111111111111111E19
#{of:formatThousands(11111111111111111111.1)}

// java.util.UnknownFormatConversionException
#{of:formatThousands(111111111111111111111.1)}

Niciun comentariu:

Trimiteți un comentariu