PHP에서 float 값을 비교하기 위한 코드는 다음과 같습니다. -
예시
<?php
$a = 2.5;
$b = 3.5;
echo $a;
echo "\n$b";
if($a == $b) {
echo "\nBoth the values are equal!";
} else {
echo "\nBoth the values aren\'t equal";
}
?> 출력
이것은 다음과 같은 출력을 생성합니다-
2.5 3.5 Both the values aren\'t equal
예시
이제 다른 예를 살펴보겠습니다 -
<?php
$a = 1.967;
$b = 1.969;
echo $a;
echo "\n$b";
if((round($a, 2)) == (round($b, 2))) {
echo "\nBoth the values are equal!";
} else {
echo "\nBoth the values aren\'t equal";
}
?> 출력
이렇게 하면 다음 예제가 생성됩니다-
1.967 1.969 Both the values are equal!