Java Float Number Format formatFloat(float input, int numDecimals)

Here you can find the source of formatFloat(float input, int numDecimals)

Description

format Float

License

Open Source License

Declaration

static public float formatFloat(float input, int numDecimals) 

Method Source Code

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

public class Main {
    static public float formatFloat(float input, int numDecimals) {
        float m = (float) Math.pow(10, numDecimals);
        return Math.round(input * m) / m;
    }/*from  w ww .  j  ava2 s.  com*/

    static public int round(float input) {
        return Math.round(input);
    }
}

Related

  1. formatFloat(double num)
  2. formatFloat(double number, int precision)
  3. formatFloat(double value, int decimals)
  4. formatFloat(float f)
  5. formatFloat(float num, int width, int precision)
  6. formatFloat(float val)
  7. formatFloat(String value)