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

doubletoParse(double d)
to Parse
double resultado;
Locale locale = new Locale("en", "UK");
String pattern = "###.##";
DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale);
decimalFormat.applyPattern(pattern);
String format = decimalFormat.format(d);
resultado = Double.parseDouble(format);
return resultado;
...
StringtoPrecision(double I, int digits1, int digits2)
to Precision
if (digits2 == 0)
    return (String.valueOf((int) Math.round(I)));
StringBuffer strbuf = new StringBuffer("");
for (int i = 0; i < digits1 - 1; i++)
    strbuf.append("#");
strbuf.append("0.");
for (int i = 0; i < digits2; i++)
    strbuf.append("#");
...
StringtoScientific(double I, int digits)
to Scientific
StringBuffer strbuf = new StringBuffer("0.");
for (int i = 0; i < digits; i++)
    strbuf.append("#");
strbuf.append("E0");
DecimalFormat df = new DecimalFormat(strbuf.toString());
return (df.format(I));
StringtoSplitDecimalString(Double num, int decimal)
to Split Decimal String
if (num == null) {
    return "";
String str = num.toString();
String formatStr = "###,###.";
for (int i = 0; i < decimal; ++i) {
    formatStr = formatStr + "0";
DecimalFormat df = new DecimalFormat(formatStr);
try {
    str = df.format(num);
} catch (Exception localException) {
return str;
StringtoStockPrice(double value)
Convert the value to stock price representation.
return stockPriceNumberFormat.get().format(value);
StringtoString(double d)
to String
return SIMPLE_ORDINATE_FORMAT.format(d);
StringtoString(double d)
to String
return new DecimalFormat("#,##0.00").format(d);
StringtoString(double d, int precision)
to String
StringBuffer sb = new StringBuffer();
if (precision > 0) {
    DecimalFormat df = getFormatter(precision);
    sb.append(df.format(d));
} else {
    sb.append(d);
return sb.toString();
...
StringtoString(double value)
Converts a double to a string without the trailing fractional zero.
return new DecimalFormat("0.#################").format(value);
StringtoString(double value)
to String
value = round(value);
if (value % 1 == 0) {
    return NumberFormat.getNumberInstance().format((int) value);
return NumberFormat.getNumberInstance().format(value);