Java Decimal Format toString(double value)

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

Description

to String

License

Open Source License

Declaration

public static String toString(double value) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Main {

    public static String toString(double value) {
        if (Double.isNaN(value)) {
            return "NaN";
        }// w  ww  .j  a va2  s  .c o m
        BigDecimal bigDecimal = new BigDecimal(value);
        return bigDecimal.toString();
    }

    public static String toString(double value, int bit) {
        StringBuilder builder = new StringBuilder("#.");
        if (bit == 0) {
            builder.append("#");
        } else {
            for (int i = 0; i < bit; i++) {
                builder.append("#");
            }
        }
        DecimalFormat decimalFormat = new DecimalFormat(builder.toString());
        return decimalFormat.format(value);
    }
}

Related

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