Here you can find the source of toString(double value)
public static String toString(double value)
//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); } }