Here you can find the source of roundFloatToPlace(float f, int place)
Parameter | Description |
---|---|
f | a parameter |
place | number of places after decimal point, between 0 and 9 |
public static float roundFloatToPlace(float f, int place)
//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; } }