The example in this article describes the method of PHP floating-point comparison size. Share to everyone for your reference, as follows:
<?php/** * Floating point number is generally not used to compare the size, but we can use a flexible way * with var_dump output floating point is not see the effect, you can use Serialize view * 1.round 2. Floating-point conversion to String * * Convert to String method: * Pass Precede it with (string) or use the Strval () function to convert to a string * in an expression that requires a string, the string automatically shifts, such as when you use the function echo () or print (), or when a variable and a string are compared, the change occurs * TR The UE turns to 1, and false turns to an empty string */$a = 13.2, $b =: $c = $a/$b;//The actual value is the d:0. 54999999999999993338661852249060757458209991455078125;echo Serialize ($c). '
';//echo $c. '
';//output will be displayed as 0.55 actual value is smaller than he//so direct and 0.55 comparison size is not established if ($c = = 0.55) { echo ' nothing ';} $c = Round ($c, 2);//round processing if ($c = = 0.55) { echo ' OK ';} echo "
";//Force conversion to string//$c = (string) $c;//$c = Strval ($c); if (" $c "= = 0.55) { echo ' OK ';}? >
The results of the operation are as follows:
D:0.54999999999999993338661852249060757458209991455078125;0.55okok
Read more about PHP related content readers can view the topic: "PHP Operations and Operator Usage Summary", "PHP Basic Grammar Primer Tutorial", "PHP error and Exception handling method summary" and "PHP common functions and Skills summary"
I hope this article is helpful to you in PHP programming.
The above describes the PHP floating point comparison method, including the contents of the content, I hope that the PHP tutorial interested in a friend helpful.