Search in sources :

Example 71 with DecimalFormatSymbols

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);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 72 with DecimalFormatSymbols

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());
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) AccountingDto(org.mifos.platform.accounting.AccountingDto) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 73 with DecimalFormatSymbols

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();
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 74 with DecimalFormatSymbols

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);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal)

Example 75 with DecimalFormatSymbols

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;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols)

Aggregations

DecimalFormatSymbols (java.text.DecimalFormatSymbols)133 DecimalFormat (java.text.DecimalFormat)93 NumberFormat (java.text.NumberFormat)14 Locale (java.util.Locale)13 ParseException (java.text.ParseException)8 BigDecimal (java.math.BigDecimal)7 Currency (java.util.Currency)7 ObjectInputStream (java.io.ObjectInputStream)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 ParsePosition (java.text.ParsePosition)5 BufferedChecksumIndexInput (org.apache.lucene.store.BufferedChecksumIndexInput)5 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)5 IndexInput (org.apache.lucene.store.IndexInput)5 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4 BytesRef (org.apache.lucene.util.BytesRef)4 ArrayList (java.util.ArrayList)3