use of java.text.DecimalFormatSymbols in project HanLP by hankcs.
the class Matrix method print.
/**
* Print the matrix to the output stream. Line the elements up in
* columns with a Fortran-like 'Fw.d' style format.
*
* @param output Output stream.
* @param w Column width.
* @param d Number of digits after the decimal.
*/
public void print(PrintWriter output, int w, int d) {
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
format.setMinimumIntegerDigits(1);
format.setMaximumFractionDigits(d);
format.setMinimumFractionDigits(d);
format.setGroupingUsed(false);
print(output, format, w + 2);
}
use of java.text.DecimalFormatSymbols in project head by mifos.
the class AccountingDataCacheManagerTest method testAccoutingDataFromCache.
@Test
public void testAccoutingDataFromCache() throws Exception {
List<AccountingDto> data = new ArrayList<AccountingDto>();
data.add(new AccountingDto("branch", "2010-10-12", "RECEIPT", "234324", "GLCODE NAME", "5", "546"));
data.add(new AccountingDto("branch", "2010-10-12", "RECEIPT", "234324", "GLCODE NAME", "5", "546"));
LocalDate date = new LocalDate(2010, 10, 12);
String cacheFileName = cacheManager.getCacheFileName(date, date);
cacheManager.writeAccountingDataToCache(data, cacheFileName);
List<AccountingDto> accountingData = cacheManager.getExportDetails(cacheFileName);
Assert.assertEquals(2, accountingData.size());
DecimalFormat df = new DecimalFormat("#.0", new DecimalFormatSymbols(Locale.ENGLISH));
for (AccountingDto dto : accountingData) {
Assert.assertEquals("branch;2010-10-12;RECEIPT;234324;GLCODE NAME;" + df.format(5.0) + ";" + df.format(546.0), dto.toString());
Assert.assertEquals("GLCODE NAME", dto.getGlCodeName());
}
}
use of java.text.DecimalFormatSymbols in project head by mifos.
the class LocalizationConverter method loadDecimalFormats.
private void loadDecimalFormats() {
if (locale == null) {
throw new RuntimeException("The current locale is not set for LocalizationConverter.");
}
// use this English locale for decimal format for 1.1 release
boolean localeSupported = isLocaleSupported(NumberFormat.getAvailableLocales(), locale);
if (!localeSupported) {
throw new RuntimeException("NumberFormat class doesn't support this country code: " + locale.getCountry() + " and language code: " + locale.getLanguage());
}
NumberFormat format = DecimalFormat.getInstance(locale);
if (format instanceof DecimalFormat) {
decimalFormat = (DecimalFormat) format;
decimalFormatForMoney = buildDecimalFormat(digitsBeforeDecimalForMoney, digitsAfterDecimalForMoney, (DecimalFormat) decimalFormat.clone(), Boolean.TRUE);
decimalFormatForInterest = buildDecimalFormat(digitsBeforeDecimalForInterest, digitsAfterDecimalForInterest, (DecimalFormat) decimalFormat.clone(), Boolean.FALSE);
DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols();
decimalFormatSymbol = decimalFormatSymbols.getDecimalSeparator();
minusSign = decimalFormatSymbols.getMinusSign();
}
}
use of java.text.DecimalFormatSymbols in project gradle by gradle.
the class LocaleSafeDecimalFormat method parse.
/**
* Regardless of the default locale, comma ('.') is used as decimal separator
*
* @param source
* @return
* @throws ParseException
*/
public BigDecimal parse(String source) throws ParseException {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat format = new DecimalFormat("#.#", symbols);
format.setParseBigDecimal(true);
return (BigDecimal) format.parse(source);
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class Scanner method getFloatPattern.
private Pattern getFloatPattern() {
if (decimalFormat == null) {
decimalFormat = (DecimalFormat) NumberFormat.getInstance(locale);
}
if (cachedFloatPattern != null) {
return cachedFloatPattern;
}
DecimalFormatSymbols dfs = decimalFormat.getDecimalFormatSymbols();
String digit = "([0-9]|(\\p{javaDigit}))";
String nonZeroDigit = "[\\p{javaDigit}&&[^0]]";
String numeral = getNumeral(digit, nonZeroDigit);
String decimalSeparator = "\\" + dfs.getDecimalSeparator();
String decimalNumeral = "(" + numeral + "|" + numeral + decimalSeparator + digit + "*+|" + decimalSeparator + digit + "++)";
String exponent = "([eE][+-]?" + digit + "+)?";
String decimal = "(([-+]?" + decimalNumeral + "(" + exponent + "?)" + ")|" + "(" + addPositiveSign(decimalNumeral) + "(" + exponent + "?)" + ")|" + "(" + addNegativeSign(decimalNumeral) + "(" + exponent + "?)" + "))";
String hexFloat = "([-+]?0[xX][0-9a-fA-F]*\\.[0-9a-fA-F]+([pP][-+]?[0-9]+)?)";
String localNaN = dfs.getNaN();
String localeInfinity = dfs.getInfinity();
String nonNumber = "(NaN|\\Q" + localNaN + "\\E|Infinity|\\Q" + localeInfinity + "\\E)";
String signedNonNumber = "((([-+]?(" + nonNumber + ")))|" + "(" + addPositiveSign(nonNumber) + ")|" + "(" + addNegativeSign(nonNumber) + "))";
cachedFloatPattern = Pattern.compile(decimal + "|" + hexFloat + "|" + signedNonNumber);
return cachedFloatPattern;
}
Aggregations