Java Fraction Format formatFloat(float number, int numberOfAfterDot)

Here you can find the source of formatFloat(float number, int numberOfAfterDot)

Description

format Float

License

Open Source License

Declaration

public static float formatFloat(float number, int numberOfAfterDot) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {

    public static float formatFloat(float number, int numberOfAfterDot) {
        String format = ".";
        for (int i = 0; i < numberOfAfterDot; i++) {
            format += "0";
        }//from   ww  w  . j  a  va  2  s.com
        DecimalFormat decimalFormat = new DecimalFormat(format);
        String tmp = decimalFormat.format(number);
        return Float.parseFloat(tmp);
    }
}

Related

  1. formateNum(double num)
  2. formatFloat(double val1, double val2)
  3. formatFloat(float f, String format)
  4. formatFloat(float num)
  5. formatFloat(float number)
  6. formatFloat(Float someFloat)
  7. FormatFloat(float value, int point)
  8. formatFloat(String format, double f)
  9. formatFloatToStr(Float str)