Java Fraction Format formatNumber(Float d, int scalar)

Here you can find the source of formatNumber(Float d, int scalar)

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(Float d, int scalar) throws Exception 

Method Source Code

//package com.java2s;
/**/*  w  w w. j a v  a 2 s  .c om*/
 * Copyright (C) 2002-2005 WUZEWEN. All rights reserved.
 * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {

    public static String formatNumber(Double d, int scalar) throws Exception {
        double temp = d.doubleValue();
        return formatNumber(temp, scalar);
    }

    public static String formatNumber(Float d, int scalar) throws Exception {
        float temp = d.floatValue();
        return formatNumber(temp, scalar);
    }

    public static String formatNumber(double number, int scalar) throws Exception {
        String zero = "000000000000000000000000000000";
        String format = "##0." + zero.substring(0, scalar);
        NumberFormat nf = new DecimalFormat(format);
        return nf.format(number);
    }

    public static String formatNumber(float number, int scalar) throws Exception {
        String zero = "000000000000000000000000000000";
        String format = "##0." + zero.substring(0, scalar);
        NumberFormat nf = new DecimalFormat(format);
        return nf.format(number);
    }
}

Related

  1. formatNumber(double paramDouble, int paramInt)
  2. formatNumber(double pValue)
  3. formatNumber(double value)
  4. formatNumber(double value, double epsilon)
  5. formatNumber(final double number)
  6. formatNumber(float num, String format)
  7. formatNumber(int fractionDigits, double value)
  8. formatNumber(String Format, double Num)
  9. formatNumber(String format, double number)