Java Fraction Format formatted_string(double number)

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

Description

formattestring

License

Open Source License

Declaration

public static String formatted_string(double number) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Jay Unruh, Stowers Institute for Medical Research.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 ******************************************************************************/

import java.text.DecimalFormat;

public class Main {
    public static String formatted_string(double number) {
        double absnumber = Math.abs(number);
        if (absnumber >= 1000.0 || absnumber < 0.01) {
            DecimalFormat expformat = new DecimalFormat("0.00E0");
            return expformat.format(number);
        } else {//w w w.  j  a  va 2s .  c om
            if (absnumber >= 100.0) {
                DecimalFormat tempformat = new DecimalFormat("000.0");
                return tempformat.format(number);
            } else {
                if (absnumber >= 10.0) {
                    DecimalFormat tempformat = new DecimalFormat("00.00");
                    return tempformat.format(number);
                } else {
                    DecimalFormat tempformat = new DecimalFormat("0.000");
                    return tempformat.format(number);
                }
            }
        }
    }
}

Related

  1. formatPrice(Double price)
  2. formatQuantity(Double quantity)
  3. formatRate(double events, double time, String event)
  4. formatSimpleDecimal(double d)
  5. formatSpeed(float speed)
  6. formatToEightPlaces(double pValue)
  7. formatToString(Double v)
  8. formatTSYS(double tsys)
  9. formatTwoDecimalsToStr(float num)