Ignore:
Timestamp:
2017-10-29T14:57:41+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #14602 - allow both dot and comma decimal separator everywhere possible for user-entered values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProvider.java

    r12931 r13050  
    22package org.openstreetmap.josm.tools;
    33
     4import java.text.DecimalFormat;
    45import java.text.DecimalFormatSymbols;
     6import java.text.NumberFormat;
    57import java.text.spi.DecimalFormatSymbolsProvider;
    68import java.util.Locale;
     
    2830        return I18n.getAvailableTranslations();
    2931    }
     32
     33    /**
     34     * Returns a new {@code double} initialized to the value represented by the specified {@code String},
     35     * allowing both dot and comma decimal separators.
     36     *
     37     * @param  s   the string to be parsed.
     38     * @return the {@code double} value represented by the string argument.
     39     * @throws NullPointerException  if the string is null
     40     * @throws NumberFormatException if the string does not contain a parsable {@code double}.
     41     * @see    Double#parseDouble(String)
     42     * @since 13050
     43     */
     44    public static double parseDouble(String s) throws NumberFormatException {
     45        String text = s;
     46        NumberFormat format = DecimalFormat.getInstance();
     47        if (format instanceof DecimalFormat) {
     48            char decimalSeparator = ((DecimalFormat) format).getDecimalFormatSymbols().getDecimalSeparator();
     49            text = text.replace('.', decimalSeparator).replace(',', decimalSeparator);
     50        }
     51        return Double.parseDouble(text);
     52    }
    3053}
Note: See TracChangeset for help on using the changeset viewer.