Java Decimal Format sanitizeDouble(String value)

Here you can find the source of sanitizeDouble(String value)

Description

Normalizes the decimal separator for the user's locale.

License

Open Source License

Declaration

public static String sanitizeDouble(String value) 

Method Source Code

//package com.java2s;
// the Bio-Formats library, licensed according to Simplified BSD, as follows:

import java.text.DecimalFormatSymbols;

public class Main {
    /** Normalizes the decimal separator for the user's locale. */
    public static String sanitizeDouble(String value) {
        value = value.replaceAll("[^0-9,\\.]", "");
        final char separator = new DecimalFormatSymbols().getDecimalSeparator();
        final char usedSeparator = separator == '.' ? ',' : '.';
        value = value.replace(usedSeparator, separator);
        try {/*from  w w  w.  ja va 2s  . c  o m*/
            Double.parseDouble(value);
        } catch (final Exception e) {
            value = value.replace(separator, usedSeparator);
        }
        return value;
    }
}

Related

  1. randomGenLat(Double latstart, Double latend)
  2. randomGenLngLat(Double lngstart, Double lngend, Double latstart, Double latend)
  3. readThisDouble(final String value)
  4. renderDouble(double value, int precision)
  5. replaceCommaByPoint(String doubleString, Locale loc)
  6. singleDecimalDigit(double d)
  7. string2Double(String s)
  8. strParaDouble(String s, double valorPadrao)
  9. to3DP(double number)