use of java.text.DecimalFormatSymbols in project jgnash by ccavanaugh.
the class CommodityFormat method getShortNumberFormat.
/**
*
* @param scale scale of the simple number
* @return thread safe {@code NumberFormat}
*/
public static NumberFormat getShortNumberFormat(final int scale) {
final ThreadLocal<DecimalFormat> o = simpleInstanceMap.get(scale);
if (o != null) {
return o.get();
}
final ThreadLocal<DecimalFormat> threadLocal = ThreadLocal.withInitial(() -> {
final DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance();
final DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
dfs.setCurrencySymbol("");
df.setDecimalFormatSymbols(dfs);
df.setMaximumFractionDigits(scale);
// required for some locale
df.setMinimumFractionDigits(df.getMaximumFractionDigits());
// for positive suffix padding for fraction alignment
int negSufLen = df.getNegativeSuffix().length();
if (negSufLen > 0) {
char[] pad = new char[negSufLen];
for (int i = 0; i < negSufLen; i++) {
pad[i] = ' ';
}
df.setPositiveSuffix(new String(pad));
}
return df;
});
simpleInstanceMap.put(scale, threadLocal);
return threadLocal.get();
}
use of java.text.DecimalFormatSymbols in project jdk8u_jdk by JetBrains.
the class NumberFormatProviderImpl method getInstance.
private NumberFormat getInstance(Locale locale, int choice) {
if (locale == null) {
throw new NullPointerException();
}
LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
if (choice == INTEGERSTYLE) {
format.setMaximumFractionDigits(0);
format.setDecimalSeparatorAlwaysShown(false);
format.setParseIntegerOnly(true);
} else if (choice == CURRENCYSTYLE) {
adjustForCurrencyDefaultFractionDigits(format, symbols);
}
return format;
}
use of java.text.DecimalFormatSymbols in project tika by apache.
the class OOXMLParserTest method testBigIntegersWGeneralFormat.
@Test
public void testBigIntegersWGeneralFormat() throws Exception {
//TIKA-2025
String xml = getXML("testEXCEL_big_numbers.xlsx").xml;
//15 digit number
assertContains("123456789012345", xml);
//15 digit formula
assertContains("123456789012346", xml);
Locale locale = LocaleUtil.getUserLocale();
DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
//16 digit number is treated as scientific notation as is the 16 digit formula
assertContains("1" + symbols.getDecimalSeparator() + "23456789012345E+15</td>\t" + "<td>1" + symbols.getDecimalSeparator() + "23456789012345E+15", xml);
}
use of java.text.DecimalFormatSymbols in project symja_android_library by axkr.
the class NumberTest method testNumberFormat.
/**
* Format a double value with a <code>java.text.DecimalFormat</code> object.
*/
public void testNumberFormat() {
StringBuilder buf = new StringBuilder();
try {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
DecimalFormat decimalFormat = new DecimalFormat("0.0####", otherSymbols);
OutputFormFactory factory = OutputFormFactory.get(true, false, decimalFormat);
IExpr expr = F.num("12345.123456789");
factory.convert(buf, expr);
} catch (IOException e) {
e.printStackTrace();
}
assertEquals(buf.toString(), "12345.12346");
}
use of java.text.DecimalFormatSymbols in project cytoscape-api by cytoscape.
the class ObjectPosition method shortString.
private String shortString() {
// force the locale to US so that we consistently serialize
final DecimalFormat df = new DecimalFormat("#0.00;-#0.00", new DecimalFormatSymbols(Locale.US));
final StringBuilder sb = new StringBuilder();
sb.append(targetAnchor.getShortName());
sb.append(",");
sb.append(objectAnchor.getShortName());
sb.append(",");
sb.append(justify.getShortName());
sb.append(",");
sb.append(df.format(xOffset));
sb.append(",");
sb.append(df.format(yOffset));
return sb.toString();
}
Aggregations