nickolasburr/floatcmp

Compare floating-point numbers with optional precision.

1.1.0 2025-02-18 04:44 UTC

This package is auto-updated.

Last update: 2025-03-04 04:35:16 UTC


README

Description

Compare floating-point numbers with optional precision.

Installation

composer require nickolasburr/floatcmp:^1.0

Usage

use function floatcmp;

$a = 0.00528690;
$b = 0.00528;

if (floatcmp($a, $b, 5) === 0) {
    /*
     * $a and $b are equal at given scale precision.
     *
     * Unlike a floating-point arithmetic library,
     * floatcmp() does not apply rounding to its
     * arguments but instead takes a fixed-width
     * scale approach like bccomp(). When bcmath
     * is available, floatcmp() will use bccomp()
     * for the float comparison.
     */
}