Here you can find the source of formatted_string(double number)
public static String formatted_string(double number)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 Jay Unruh, Stowers Institute for Medical Research. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v2.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html ******************************************************************************/ import java.text.DecimalFormat; public class Main { public static String formatted_string(double number) { double absnumber = Math.abs(number); if (absnumber >= 1000.0 || absnumber < 0.01) { DecimalFormat expformat = new DecimalFormat("0.00E0"); return expformat.format(number); } else {//w w w. j a va 2s . c om if (absnumber >= 100.0) { DecimalFormat tempformat = new DecimalFormat("000.0"); return tempformat.format(number); } else { if (absnumber >= 10.0) { DecimalFormat tempformat = new DecimalFormat("00.00"); return tempformat.format(number); } else { DecimalFormat tempformat = new DecimalFormat("0.000"); return tempformat.format(number); } } } } }