Java Float Number Format formatFloat(double num)

Here you can find the source of formatFloat(double num)

Description

format Float

License

Open Source License

Declaration

public static String formatFloat(double num) 

Method Source Code

//package com.java2s;
/*//from  w w w. j a va  2s .co  m
 * File: SCD_LogUtils.java 
 *
 * Copyright (C) 2002-2006, Peter Peterson, Ruth Mikkelson
 *
 * This program 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 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 *
 * Contact : Peter F. Peterson <pfpeterson@anl.gov>
 *           Intense Pulsed Neutron Source Division
 *           Argonne National Laboratory
 *           9700 South Cass Avenue, Bldg 360
 *           Argonne, IL 60439-4845, USA
 *
 * This work was supported by the Intense Pulsed Neutron Source Division
 * of Argonne National Laboratory, Argonne, IL 60439-4845, USA.
 * Some of this work was supported by the National Science Foundation under
 * grant number DMR-0218882
 * For further information, see <http://www.pns.anl.gov/ISAW/>
 *
 * $Log$
 * Revision 1.2  2008/01/29 19:45:49  rmikk
 * Replaced Peak by IPeak
 *
 * Revision 1.1  2006/12/19 05:16:28  dennis
 * Collection of static methods used by the various versions of the
 * SCD integrate operators.  These particular methods were factored
 * out of the Integrate_new class.
 *
 *
 */

public class Main {
    public static String formatFloat(double num) {
        StringBuffer text = new StringBuffer(Double.toString(num));
        int index = text.toString().indexOf(".");
        if (index < 0) {
            text.append(".");
            index = text.toString().indexOf(".");
        }
        text.append("00");
        text.delete(index + 3, text.length());

        while (text.length() < 7)
            text.insert(0, " ");

        return text.toString();
    }
}

Related

  1. formatFloat(double number, int precision)
  2. formatFloat(double value, int decimals)
  3. formatFloat(float f)
  4. formatFloat(float input, int numDecimals)