Java Locale Format format(final double num, final int prec)

Here you can find the source of format(final double num, final int prec)

Description

format

License

Open Source License

Declaration

public static String format(final double num, final int prec) 

Method Source Code


//package com.java2s;
/*//w w w .  j a v a  2s.co  m
 * Copyright (C) Justo Montiel, David Torres, Sergio Gomez, Alberto Fernandez
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see
 * <http://www.gnu.org/licenses/>
 */

import java.text.NumberFormat;
import java.util.Locale;

public class Main {
    static NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);

    public static String format(final double num, final int prec) {
        nf.setMinimumFractionDigits(prec);
        nf.setMaximumFractionDigits(prec);
        nf.setGroupingUsed(false);

        return nf.format(num);
    }
}

Related

  1. format(double number, int fractionDigits)
  2. format(double value)
  3. format(double values, boolean doNotFormat)
  4. format(final Date date, final String format)
  5. format(final Date date, final String format)
  6. format(final String bundleKey, final String messageKey, final Locale locale, final Object... arguments)
  7. format(int[] a)
  8. format(Locale locale, ResourceBundle bundle, String key, Object... args)
  9. format(Locale locale, String key, Object... arguments)