PHP floating-point comparison size method, PHP floating-point size _php Tutorial

Source: Internet
Author: User

PHP floating-point comparison size method, PHP floating-point size


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.

Articles you may be interested in:

    • PHP implements a method to compare two string date sizes
    • Compare time-size instances in PHP
    • PHP compares two absolute time sizes
    • PHP Compare the size of the values in a multidimensional array to sort the implementation code
    • A detailed description of the PHP comparison operator
    • Two float (floating point) Comparison example analysis in PHP
    • PHP comparison of two string length methods
    • Calculation and comparison of floating-point numbers in PHP and the solution to integer inaccuracy
    • PHP comparison of similar string methods
    • Calculation of floating-point numbers in PHP and the solution of inaccurate rounding

http://www.bkjia.com/PHPjc/1099056.html www.bkjia.com true http://www.bkjia.com/PHPjc/1099056.html techarticle PHP floating-point comparison size method, PHP floating-point Size 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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.