Java Utililty Methods Decimal Format

List of utility methods to do Decimal Format

Description

The list of methods to do Decimal Format are organized into topic(s).

Method

DoublerandomGenLat(Double latstart, Double latend)
random Gen Lat
Random ran = new Random();
double latdis = latend - latstart;
return Double.parseDouble(df.format(ran.nextDouble() * latdis + latstart));
voidrandomGenLngLat(Double lngstart, Double lngend, Double latstart, Double latend)
random Gen Lng Lat
Random ran = new Random();
Double lngdis = lngend - lngstart;
double latdis = latend - latstart;
int count = 0;
while (count < 200) {
    count++;
    Double d1 = Double.parseDouble(df.format(ran.nextDouble() * lngdis + lngstart));
    Double d2 = Double.parseDouble(df.format(ran.nextDouble() * latdis + latstart));
...
doublereadThisDouble(final String value)
read This Double
double res;
final String trimmed = value.trim();
if (trimmed.toUpperCase().equals("NAN"))
    res = 0;
else {
    try {
        res = shortFormat.parse(trimmed).doubleValue();
    } catch (final ParseException e) {
...
StringrenderDouble(double value, int precision)
render Double
return renderDouble(value, precision, ',');
StringreplaceCommaByPoint(String doubleString, Locale loc)
If a decimal number contains a comma and no point, and if the given locale uses a comma for decimal separator, the comma is replaced by a point.
DecimalFormatSymbols symb = new DecimalFormatSymbols(loc);
if (symb.getDecimalSeparator() == ',') {
    if (doubleString.indexOf(',') >= 0 && doubleString.indexOf(',') == doubleString.lastIndexOf(',')
            && doubleString.indexOf('.') == -1) {
        return doubleString.replace(',', '.');
return doubleString;
...
StringsanitizeDouble(String value)
Normalizes the decimal separator for the user's locale.
value = value.replaceAll("[^0-9,\\.]", "");
final char separator = new DecimalFormatSymbols().getDecimalSeparator();
final char usedSeparator = separator == '.' ? ',' : '.';
value = value.replace(usedSeparator, separator);
try {
    Double.parseDouble(value);
} catch (final Exception e) {
    value = value.replace(separator, usedSeparator);
...
StringsingleDecimalDigit(double d)
single Decimal Digit
return new DecimalFormat("#.#").format(d);
Doublestring2Double(String s)
string Double
return mDecFmt.parse(s).doubleValue();
doublestrParaDouble(String s, double valorPadrao)
str Para Double
try {
    return Double.parseDouble(s.trim());
} catch (Exception ex) {
    return valorPadrao;
doubleto3DP(double number)
to DP
return Double.valueOf(FORMAT.format(number));