Java Fraction Format formatdouble(double number)

Here you can find the source of formatdouble(double number)

Description

formatdouble

License

Open Source License

Declaration

static public String formatdouble(double number) 

Method Source Code

//package com.java2s;
/* //from  w w  w. jav  a  2  s .  c o  m
 * Copyright 2012 Devoteam http://www.devoteam.com
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * 
 * This file is part of Multi-Protocol Test Suite (MTS).
 * 
 * Multi-Protocol Test Suite (MTS) 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.
 * 
 * Multi-Protocol Test Suite (MTS) 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 Multi-Protocol Test Suite (MTS).
 * If not, see <http://www.gnu.org/licenses/>.
 * 
 */

import java.text.DecimalFormat;

public class Main {
    private static DecimalFormat df = new DecimalFormat("##,###,###,###,###,##0.####");
    private static DecimalFormat dfMicro = new DecimalFormat("0.####E0");

    static public String formatdouble(double number) {
        if (Math.abs(number) > 1e-4 || number == 0) {
            return df.format(number);
        } else {
            return dfMicro.format(number);
        }
    }
}

Related

  1. formatDouble(Double in)
  2. formatDouble(double inVal, int inNumPlaces, boolean pad)
  3. formatDouble(Double num)
  4. formatDouble(double num)
  5. formatDouble(Double num)
  6. formatDouble(double number)
  7. formatDouble(double number)
  8. formatDouble(double number, int decimalDigits)
  9. formatDouble(double number, int integerDigits, int fractionDigits)