Here you can find the source of doubleToString(final double number)
public static String doubleToString(final double number)
//package com.java2s; /*//w w w . j av a 2 s .com * Copyright 2009-2015 Hewlett-Packard Development Company, L.P. * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. */ import java.text.DecimalFormat; public class Main { public static String doubleToString(final double number) { final double abs = Math.abs(number); final DecimalFormat format; if (abs < 100.0) { format = new DecimalFormat("#.#####"); } else if (abs < 1000.0) { format = new DecimalFormat("#.####"); } else if (abs < 10000.0) { format = new DecimalFormat("#.###"); } else if (abs < 30000.0) { format = new DecimalFormat("#.##"); } else if (abs < 100000.0) { format = new DecimalFormat("#.#"); } else { format = new DecimalFormat("#"); } return format.format(number); } }