lno.setDefault();
return formatNumber(n, lno);
}
public String formatNumber(final Number n, final LotusNumberOptions lno) {
NumberFormat nf;
/*
* It would have been more convenient to use NumberFormat.getInstance(locale, style),
* but this method is private in com.ibm.icu_3.8.1.v20120530.jar.
* (Seems to be public as of ICU 4.2.)
*/
if (lno.format == 'C')
nf = NumberFormat.getCurrencyInstance(iLocale);
else if (lno.format == 'S')
nf = NumberFormat.getScientificInstance(iLocale);
else if (lno.format == '%')
nf = NumberFormat.getPercentInstance(iLocale);
else
nf = NumberFormat.getNumberInstance(iLocale);
nf.setGroupingUsed(lno.useGrouping);
nf.setMaximumIntegerDigits(1000);
if (lno.fractionDigits != -1) {
nf.setMinimumFractionDigits(lno.fractionDigits);
nf.setMaximumFractionDigits(lno.fractionDigits);
} else
nf.setMaximumFractionDigits(1000);
String ret = nf.format(n);
do {
if (lno.format != 'G' || ret.length() <= 15)
break;
/*
* In this case, Lotus implicitly switches to scientific style.
* When useGrouping is in effect, the limit decreases from 15 to 12 in Lotus
* (i.e. the grouping bytes are likewise counted), but we are not going to
* imitate this strange behaviour.
*/
String tester = ret;
if (lno.useGrouping) {
nf.setGroupingUsed(false);
tester = nf.format(n);
}
int minus = (tester.charAt(0) == '-') ? 1 : 0;
int lh = tester.length();
if (lh - minus <= 15)
break;
int komma = minus;
for (; komma < lh; komma++)
if (!Character.isDigit(tester.charAt(komma)))
break;
if (komma - minus <= 15)
break;
nf = NumberFormat.getScientificInstance(iLocale);
nf.setGroupingUsed(lno.useGrouping);
ret = nf.format(n);
} while (false);
if (lno.negativeAsParentheses && ret.charAt(0) == '-')
ret = '(' + ret.substring(1) + ')';
return ret;
}