Java Fraction Format format(double val)

Here you can find the source of format(double val)

Description

format

License

Open Source License

Declaration

public static String format(double val) 

Method Source Code

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

Related

  1. format(double number, int digits)
  2. format(double number, String fmt)
  3. format(double price)
  4. format(double val)
  5. format(double val)
  6. format(double value)
  7. format(double value)
  8. format(double value)
  9. format(double value)