Java Decimal Format toString(final double value, final int maxDecimalPlaces)

Here you can find the source of toString(final double value, final int maxDecimalPlaces)

Description

to String

License

Open Source License

Declaration

public static String toString(final double value, final int maxDecimalPlaces) 

Method Source Code

//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);
    }
}

Related

  1. toString(double value, int precision)
  2. toString(double[] array)
  3. toString(Double[] input)
  4. toString(double[][] a, int decimals)
  5. toString(final Double value)
  6. toStringForHumans(double doubleToConvert)
  7. toStringNoDigits(double[] v)
  8. toStringScientific(double x)
  9. trim(int degree, double d)