PHP floating point size method, php floating point size. PHP floating point size comparison method. php floating point size this article describes the PHP floating point size comparison method. For your reference, the php *** floating point is generally not a PHP floating point to compare the size of the method, php floating point size
This example describes how to compare the floating point size of PHP. We will share this with you for your reference. The details are as follows:
<? Php/*** floating point numbers are generally not used to compare the size, but we can use a flexible method * using var_dump to output floating point results does not show the effect, you can use serialize to View * 1. round 2. to convert a floating point to a string **: * to convert a string by adding a string before it or using the strval () function * in a string expression, the string is automatically converted, for example, when echo () or print () is used, or when a variable is compared with a string, this transformation * true is converted to 1, false is converted into an empty string **/$ a = 13.2; $ B = 24; $ c = $ a/$ B; // The actual value is d: 0.54999999999999993338661852249060757458209991455078125; echo serialize ($ c ).'
'; // Echo $ c .'
'; // The actual value displayed in the output is smaller than the actual value of 0.55. // therefore, it is invalid to directly compare the value with 0.55 if ($ c = 0.55) {echo 'Nothing ';} $ c = round ($ c, 2); // process if ($ c = 0.55) {echo' OK ';} echo"
"; // Force convert to string // $ c = (string) $ c; // $ c = strval ($ c); if (" $ c "= 0.55) {echo 'OK';}?>
The running result is as follows:
D: 0.54999999999999993338661852249060757458209991455078125; 0.55 okok