Skip to content
Advertisement

PHP and unit testing assertions with decimals

I have a method that returns a float like 1.234567890.I want to test that it really does so. However, it seems that this returned float has different precision on different platforms so how do I assert that the returned value is 1.23456789? If I just do:

$this->assertEqual(1.23456789, $float);

Then that might fail on some platforms where there is not enough precision.

Advertisement

Answer

For greater accuracy you may consider using BCMath.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement