Here you can find the source of format(double val)
public static String format(double val)
//package com.java2s; /*//from w w w . j a v a2s. com * uDig - User Friendly Desktop Internet GIS client * (C) MangoSystem - www.mangosystem.com * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html), and the HydroloGIS BSD * License v1.0 (http://udig.refractions.net/files/hsd3-v10.html). */ import java.math.RoundingMode; import java.text.DecimalFormat; public class Main { static final int DEFAULT_NUMBER_DIGIT = 6; static final DecimalFormat df = new DecimalFormat("#.######"); public static String format(double val) { return format(val, DEFAULT_NUMBER_DIGIT); } public static String format(double val, int numberDigit) { if (Double.isNaN(val)) { return ""; } if (Double.isInfinite(val)) { return ""; } df.setMaximumFractionDigits(numberDigit); df.setRoundingMode(RoundingMode.HALF_UP); return df.format(val); } }