Java Double Number to String doubleToString(final double d, final int decimalPlaces)

Here you can find the source of doubleToString(final double d, final int decimalPlaces)

Description

double To String

License

Open Source License

Declaration

public static String doubleToString(final double d,
            final int decimalPlaces) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2014 University of Massachusetts Medical School
 * Alessandro Rigano (Program in Molecular Medicine)
 * Caterina Strambio De Castillia (Program in Molecular Medicine)
 *
 * Created by the Open Microscopy Environment inteGrated Analysis (OMEGA) team: 
 * Alex Rigano, Caterina Strambio De Castillia, Jasmine Clark, Vanni Galli, 
 * Raffaello Giulietti, Loris Grossi, Eric Hunter, Tiziano Leidi, Jeremy Luban, 
 * Ivo Sbalzarini and Mario Valle.//  w w w  .ja v  a 2s  .  co  m
 *
 * Key contacts:
 * Caterina Strambio De Castillia: caterina.strambio@umassmed.edu
 * Alex Rigano: alex.rigano@umassmed.edu
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *******************************************************************************/

import java.text.DecimalFormat;

public class Main {
    public static String doubleToString(final double d,
            final int decimalPlaces) {
        String dec = "";
        for (int i = 0; i < decimalPlaces; i++) {
            dec = dec + "#";
        }
        final DecimalFormat df = new DecimalFormat("#." + dec);
        return df.format(d);
    }
}

Related

  1. doubleToString(double value)
  2. doubleToString(double value, int afterDecimalPoint)
  3. doubleToString(double value, int fractionDigits)
  4. doubleToString(double value, int maximum, int minimum)
  5. doubleToString(double value, String format)
  6. doubleToString(final double number)
  7. doubleToSz(double dval)
  8. doubleToVisualString(double d)