Permalink
Browse files

Fix #204: use exact metric units

  • Loading branch information...
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 10<sup>n</sup> (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):
* <ul>
* <li>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 @@
<description>
<![CDATA[
Format the given number to nearest 10<sup>n</sup> (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):
<ul>
@@ -744,7 +744,7 @@
<li>9995 will appear as 10k
<li>99990 will appear as 100k
<li>9994999 will appear as 9.99m
<li>9995000 will appear as 10.0m
<li>9995000 will appear as 10m
</ul>
The format locale will be set to the one as obtained by <code>Faces#getLocale()</code>.
If the value is <code>null</code>, <code>NaN</code> or infinity, then this will return <code>null</code>.

0 comments on commit 37c4206

Please sign in to comment.