Java tutorial
//package com.java2s; public class Main { /** * Method checks if two float numbers are similar. */ public static boolean almostEqual(float a, float b, float absoluteDiff, float relativeDiff) { float diff = Math.abs(a - b); if (diff <= absoluteDiff) { return true; } a = Math.abs(a); b = Math.abs(b); float largest = (a > b) ? a : b; if (diff <= largest * relativeDiff) { return true; } return false; } }