Java Fraction Format formatDouble(double number)

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

Description

used by #toString() and #exportString()

License

Open Source License

Parameter

Parameter Description
number the double to format

Return

the formatted string

Declaration

private static String formatDouble(double number) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.RoundingMode;
import java.text.DecimalFormat;

public class Main {
    /**//from w ww. j  a  v  a 2  s.c o  m
     * used by {@link #toString()} and {@link #exportString()}
     * 
     * @param number
     *            the double to format
     * @return the formatted string
     */
    private static String formatDouble(double number) {
        DecimalFormat df;
        if (number < 0.00001d || number > 99999d) {
            df = new DecimalFormat("0.#####E0");
        } else {
            df = new DecimalFormat("###.#####");
        }

        df.setRoundingMode(RoundingMode.HALF_UP);

        return df.format(number);
    }
}

Related

  1. formatDouble(double num)
  2. formatDouble(Double num)
  3. formatDouble(Double num)
  4. formatdouble(double number)
  5. formatDouble(double number)
  6. formatDouble(double number, int decimalDigits)
  7. formatDouble(double number, int integerDigits, int fractionDigits)
  8. formatDouble(double orig)
  9. formatDouble(Double someDouble)