Here you can find the source of round(float x, float y)
public static float round(float x, float y)
//package com.java2s; public class Main { /**//from w w w . j a v a 2 s . c o m * Returns the given number rounded to the second number (rounding to arbitrary floating values). */ public static float round(float x, float y) { return y * (int) ((x + sign(x) * y / 2) / y); } /** * Returns the given number rounded to the second number (rounding to arbitrary double values). */ public static double round(double x, double y) { return y * (int) ((x + sign(x) * y / 2) / y); } /** * Returns the sign of a given number (as -1 or 1). */ public static int sign(double f) { return f < 0 ? -1 : 1; } }