sâmbătă, 23 iulie 2016

[OmniFaces utilities (2.4)] 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).

This function is available from OmniFaces 2.3, but 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:

// 9.99 kB
#{of:formatThousandsUnit(9994  , "B")}
      
// 10 MW
#{of:formatThousandsUnit(9995000 , "W")}
 
// 532 kFOO
#{of:formatThousandsUnit(532230.6483 , "FOO")}

Niciun comentariu:

Trimiteți un comentariu