nickolasburr / floatcmp
Compare floating-point numbers with optional precision.
1.1.0
2025-02-18 04:44 UTC
Requires
- php: ^8.1
Suggests
- ext-bcmath: Provides bccomp function and BcMath\Number class [>=8.4]
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. */ }