Java Decimal Format toString(double value)

Here you can find the source of toString(double value)

Description

to String

License

LGPL

Declaration

public static String toString(double value) 

Method Source Code

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

import java.math.BigDecimal;

import java.text.NumberFormat;

public class Main {
    public static String toString(double value) {
        value = round(value);/*  w  w w .  j  a v  a2s .co m*/

        if (value % 1 == 0) {
            return NumberFormat.getNumberInstance().format((int) value);
        }

        return NumberFormat.getNumberInstance().format(value);
    }

    public static double round(double value, int roundingMode) {
        return round(value, 2, roundingMode);
    }

    public static double round(double value) {
        return round(value, 2, BigDecimal.ROUND_CEILING);
    }

    public static double round(double value, int scale, int roundingMode) {
        return BigDecimal.valueOf(value).setScale(scale, roundingMode).doubleValue();
    }
}

Related

  1. toStockPrice(double value)
  2. toString(double d)
  3. toString(double d)
  4. toString(double d, int precision)
  5. toString(double value)
  6. toString(double value)
  7. toString(double value, int precision)
  8. toString(double[] array)
  9. toString(Double[] input)