Java Decimal Format renderDouble(double value, int precision)

Here you can find the source of renderDouble(double value, int precision)

Description

render Double

License

LGPL

Declaration

public static String renderDouble(double value, int precision) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

import java.text.NumberFormat;

import java.util.Locale;

public class Main {
    public static String renderDouble(double value, int precision) {
        return renderDouble(value, precision, ',');
    }//  w  ww.j av  a2s .  com

    public static String renderDouble(double value, Locale locale) {
        NumberFormat f = NumberFormat.getInstance(locale);
        return f.format(value);
    }

    public static String renderDouble(double value, int precision, char sep) {
        String format = "#.";
        for (int i = 0; i < precision; i++) {
            format += "#";
        }
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
        otherSymbols.setDecimalSeparator(sep);
        if (sep == ',') {
            otherSymbols.setGroupingSeparator('.');
        }
        DecimalFormat df = new DecimalFormat(format, otherSymbols);
        return df.format(value);
    }
}

Related

  1. PrintWith1DecAnd000Sep(double Number)
  2. randomDouble(double minDouble, double maxDouble)
  3. randomGenLat(Double latstart, Double latend)
  4. randomGenLngLat(Double lngstart, Double lngend, Double latstart, Double latend)
  5. readThisDouble(final String value)
  6. replaceCommaByPoint(String doubleString, Locale loc)
  7. sanitizeDouble(String value)
  8. singleDecimalDigit(double d)
  9. string2Double(String s)