Write a PHP program to check if two numbers are approximately equal to each other.
Note: Use abs() to compare the absolute difference of the two values to epsilon. Omit the third parameter, epsilon, to use a default value of 0.001.
<?php //Licence: https://bit.ly/2CFA5XY function approximatelyEqual($number1, $number2, $epsilon = 0.001) { if (abs($number1 - $number2) < $epsilon) return 1; else return 0; } print_r(approximatelyEqual(10.0, 10.00001)); echo("\n"); print_r(approximatelyEqual(10.0, 10.01)); ?>
Sample Output:
1 0
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer