Java Number Round roundFloatToPlace(float f, int place)

Here you can find the source of roundFloatToPlace(float f, int place)

Description

round Float To Place

License

BSD License

Parameter

Parameter Description
f a parameter
place number of places after decimal point, between 0 and 9

Declaration

public static float roundFloatToPlace(float f, int place) 

Method Source Code

//package com.java2s;
// LICENSE:      This file is distributed under the BSD license.

public class Main {
    /**//from  w w w .ja  v  a 2  s .c o  m
     * 
     * @param f
     * @param place number of places after decimal point, between 0 and 9
     * @return
     */
    public static float roundFloatToPlace(float f, int place) {
        if (place < 0)
            throw new IllegalArgumentException();
        if (place > 9)
            throw new IllegalArgumentException();
        long factor = (long) Math.pow(10, place);
        return ((float) Math.round(f * factor)) / factor;
    }
}

Related

  1. roundedSatisfaction(double value)
  2. rounder(float value, int digits)
  3. roundf(float value)
  4. roundFileLength(long nbytes)
  5. roundFloat(float value, int afterDecimalPoint)
  6. roundFloatToUnitInverse(final float graphValue, final float graphUnit)
  7. roundFormat(final int numPrec, final double number)
  8. RoundFullUp(double d)
  9. roundHalfAway(double d)