Skip to content

Release 2.0.0 with ConfigurableDoubleParser

Compare
Choose a tag to compare
@wrandelshofer wrandelshofer released this 25 Oct 10:19
· 5 commits to main since this release

The Release 2.0.0 adds a ConfigurableDoubleParser to the library.

The ConfigurableDoubleParser supports parsing of double numbers in localed formats, similar to java.text.DecimalFormat.

Examples:

        var symbols = NumberFormatSymbols.fromDecimalFormatSymbols(new DecimalFormatSymbols(Locale.GERMAN));
        boolean ignoreCase = true;
        var confdParser = new ConfigurableDoubleParser(symbols, ignoreCase);
        double confD1 = confdParser.parseDouble("123.456,89e5");
        double confD2 = confdParser.parseDouble("-0.15425,89E-5");
        System.out.println("Double value in German Locale: " + confD1);
        System.out.println("Another double value in German Locale: " + confD2);

        symbols = NumberFormatSymbols.fromDecimalFormatSymbols(new DecimalFormatSymbols(Locale.forLanguageTag("zh-CN")));
        symbols = symbols
                .withDigits(List.of('〇', '一', '二', '三', '四', '五', '六', '七', '八', '九'))
                .withExponentSeparator((Set.of("*一〇^")));

        confdParser = new ConfigurableDoubleParser(symbols, ignoreCase);
        double confZh = confdParser.parseDouble("四一.五七五三七一六六二一四五九八*一〇^七");
        System.out.println("Double value in Chinese Locale: " + confZh);