Here you can find the source of toString(final double value, final int maxDecimalPlaces)
public static String toString(final double value, final int maxDecimalPlaces)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 Vienna University of Technology. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*w ww . j av a 2 s . co m*/ * Martin Fleck (Vienna University of Technology) - initial API and implementation * * Initially developed in the context of ARTIST EU project www.artist-project.eu *******************************************************************************/ import java.text.DecimalFormat; public class Main { private static final int DEFAULT_MAX_DECIMAL_PLACES = 2; protected static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.#"); public static String toString(final double value) { return toString(value, DEFAULT_MAX_DECIMAL_PLACES); } public static String toString(final double value, final int maxDecimalPlaces) { DECIMAL_FORMAT.setMaximumFractionDigits(maxDecimalPlaces); return DECIMAL_FORMAT.format(value); } }