Here you can find the source of doubleToString(double d)
public static String doubleToString(double d)
//package com.java2s; //License from project: Apache License public class Main { public static int DOUBLE_BYTE = 4; public static String doubleToString(double d) { int length; if (d < 0.0) { length = DOUBLE_BYTE;//from www . jav a 2s . c o m } else { length = DOUBLE_BYTE - 1; } double db = 1.0; for (int i = 1; i < length; i++) { db = db * 10.0; } double nd = (double) Math.round(d * db) / db; String str = "" + nd; if (str.length() < length + 1) { for (int i = 0; i < length + 1 - str.length(); i++) { str = str + "0"; } } else { str = str.substring(0, length + 1); } return str; } }