Here you can find the source of round(final float val)
public static int round(final float val)
//package com.java2s; /**/*from ww w .j av a2 s .c o m*/ * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ public class Main { public static int round(final float val) { return floor(val + 0.5f); } public static long round(final double val) { return floor(val + 0.5d); } /** * Faster floor function. Does not handle NaN and Infinity. (Not handled when doing Math.floor and just casting * anyways, so question is if we want to handle it or not) * * @param val * Value to floor * @return Floored int value */ public static int floor(final float val) { final int intVal = (int) val; return val < 0 ? val == intVal ? intVal : intVal - 1 : intVal; } /** * Faster floor function. Does not handle NaN and Infinity. (Not handled when doing Math.floor and just casting * anyways, so question is if we want to handle it or not) * * @param val * Value to floor * @return Floored long value */ public static long floor(final double val) { final long longVal = (long) val; return val < 0 ? val == longVal ? longVal : longVal - 1 : longVal; } }