Similar numbers - how to recognize it

In the past, this article has described methods to recognize similar numbers.

For example, 500 199 Kč and 500 210 Kč are almost the same.

The solution is to calculate the proportion and compare against epsilon.

php
$x = 500199;
$y = 500210;
$epsilon = 0.001;
if (abs($x / $y) < $epsilon) {
// The numbers are similar
}

Newsletter

Nejlepsi tipy a triky o PHP do Vaseho e-mailu. Clanky a novinky nejen ze sveta PHP a programovani.