omnifaces/omnifaces

Fix #204: use exact metric units

BalusC committed Feb 2, 2016
1 parent 27f85d1 commit 37c42063aaa33581b45faa669d7be2ff8cfef883
 @@ -149,8 +149,8 @@ public static String formatPercent(Number number) { /** * Format the given number to nearest 10n (rounded to thousands), immediately suffixed (without space) * with lowercased metric unit (k, m, g, t, p and 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. * 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. * For example (with English locale): *
*
• 999.999 will appear as 999.999 @@ -194,7 +194,7 @@ public static String formatThousands(Number number) { int exp = (int) (Math.log(decimal.longValue()) / Math.log(NUMBER_1K)); BigDecimal divided = decimal.divide(BigDecimal.valueOf(Math.pow(NUMBER_1K, exp))); int maxfractions = 3 - String.valueOf(divided.longValue()).length(); return String.format(getLocale(), "%." + maxfractions + "f", divided).replaceAll("\\D?0+\$", "") + "kmgtpe".charAt(exp - 1); return String.format(getLocale(), "%." + maxfractions + "f", divided).replaceAll("\\D?0+\$", "") + "kMGTPE".charAt(exp - 1); } }
 @@ -728,7 +728,7 @@ n (rounded to thousands), immediately suffixed (without space) with lowercased metric unit (k, m, g, t, p and e), rounding half up with a precision of 3 digits, whereafter 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. For example (with English locale):
@@ -744,7 +744,7 @@
• 9995 will appear as 10k
• 99990 will appear as 100k
• 9994999 will appear as 9.99m
• 9995000 will appear as 10.0m
• 9995000 will appear as 10m
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.