Fourth PHP mathematical Operations _php Tutorial

Source: Internet
Author: User
Tags echo 7 mathematical functions
I. Numeric data types
Numeric or numeric data is typically two types of double and int in PHP.
PHP is a loosely typed scripting language, paying attention to the way the type is converted.
Copy CodeThe code is as follows:
$a = ' 5 ';
A string of numbers is also a number, which participates in mathematical operations when numbers are processed
echo is_numeric ($a); 1
Echo '
';
echo 7 + $a; 12
Echo '
';
Echo ' 7 ' + $a; 12
Echo '
';
Use. After connection, press string processing
Echo ' 7 '. $a; 75
?>

Two. Random number
The Rand () function is a simple wrapper for a random function defined in libc.
The Mt_rand () function is a good substitute for implementation.
Copy CodeThe code is as follows:
$a = rand (0,10);
echo $a;
Echo '
';
Echo Getrandmax ();
Echo '
';
$b = Mt_rand (0,10);
Echo $b;
Echo '
';
Echo Mt_getrandmax ();
Echo '
';
?>

Output
1
32767
6
2147483647
Three. Formatting data
Copy CodeThe code is as follows:
$a = 12345.6789;
Used to set how many decimal points are reserved
Echo Number_format ($a, 2);
Echo '
';
You can also change the symbolic representation of the default decimal point and the symbol for the thousand-bit
Echo Number_format ($a, 2, ' # ', ' * ')
?>

Output
12,345.68
12*345#68
Four Mathematical functions

Minimum value or minimum value in array

functions

features

abs ()

Take absolute value

floor ()

Rounding rounding

ceil ()

into a method rounding

round ()

Rounding

min ()

max () /p>

To find the maximum or maximum value in the array

Copy CodeThe code is as follows:
$a =-123456.789;
$b = Array (1, 2, 3, 4);
Echo ABS ($a);
Echo '
';
echo floor ($a);
Echo '
';
echo ceil ($a);
Echo '
';
Echo round ($a);
Echo '
';
Echo min ($b);
Echo '
';
echo Max ($b);
?>

Output
123456.789
-123457
-123456
-123457
1
4

http://www.bkjia.com/PHPjc/324809.html www.bkjia.com true http://www.bkjia.com/PHPjc/324809.html techarticle I. Numeric data type numeric or numeric data in PHP are generally two types of double and int. PHP is a loosely typed scripting language, paying attention to the way the type is converted. Copy code code as follows ...

  • 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.