PHP operators and PHP rounding functions

Source: Internet
Author: User
Tags arithmetic operators bitwise operators

Ceil--into a method to take the whole
Description
float ceil (float value)
Returns the next integer not less than value, in which value is entered if there is a fractional part. The type returned by Ceil () is still float, because the range of float values is usually larger than the integer.

Example 1. Ceil () example

<?php
Echoceil (4.3); 5
Echoceil (9.999); 10
?>


Floor--The Rounding method
Description
Float floor (float value)
Returns the next integer not less than value, rounding out the fractional part of value. The type returned by floor () is still float, because the range of float values is usually larger than the integer.

Example 1. Floor () example

<?php
Echofloor (4.3); 4
echo Floor (9.999); 9
?>


Round--Rounding a floating-point number
Description
Float round (float val [, int precision])
Returns the result of rounding Val based on the specified precision precision (number of digits after decimal point). Precision can also be negative or 0 (the default value).

Example 1. Round () example

<?php
Echoround (3.4); 3
Echoround (3.5); 4
Echoround (3.6); 4
Echo round (3.6,0); 4
Echo round (1.95583,2); 1.96
Echo Round (1241757,-3); 1242000
Echo round (5.045,2); 5.05
Echo round (5.055,2); 5.06
?>

Intval---to integer patterns of variables

Example Intval ()

<?php

Echointval (4.3); 4

Echo intval (4.6); 4

?>

I'll take a look at the arithmetic, string, logic, and comparison operators of PHP3, respectively.
1. Arithmetic operators
+: $a + $b plus $a plus $b-: $a-$b minus $a minus $b *: $a * $b multiply by $a multiplied by $b/: $a/$b divide $a by $b%: $a% $b modulo $a divided by $b remainder if two operands is an integer value (the string is converted to an integer value), and division sign ("/") returns the integer value (the divisible value). If either operand is a floating-point value, do a floating-point division.
2 string operators
String operators have only string connectors (".").   $a = "Hello"; $b = $a. "World!"; now$b = "Hello world!"
3. Assignment operators
The basic assignment operator is "=". The value of an assignment expression is the value assigned to it. For example, the value of the expression $a = 3 is 3. This allows you to do something complicated: $a = ($b = 4) + 5;  Now $a equals 9, $b is 4. In addition to the basic assignment, there are "compound operators". For all binary numbers and strings, you are allowed to do variable self-compounding operations.
For example: =: $a = 3; + =: $a + = 5;     Set $ A to 8, i.e. $a = $a + 5;   $b = "Hello"; . : $b. = "there!"; Set $b as "Hello there!", just like $b = $b. "There!";
4, bitwise operators
Bit operations allow you to set or reset the specified data. &amp: With operations, $a & $b with $a and $b are set to the result is set |: or arithmetic, $a | $b or $a or $b has a set that results in a bit ~: Non-arithmetic, ~ $a non-$a not set the result is set
5. Logical operators
And: $a and $b with $a and $b are true if the result is true or: $a or $b or $ A or $b has a true XOR result: $a XOR is true when different $b or $a and $b. :  ! $a non-$ A false then the result is true &&: $a && $b with $a and $b true results are true | |: $a | |   When a $b or $a or $b has a true result for a true comparison of two variables, there are two operators for the "and" and "or" operations, which means that two operators have different precedence 6, comparison operator comparison operators, which, like names, allow you to compare two values.   = =: $a = = $b equals $a equals $b result is true! =: $a! = $b Not equal to $a not equal to $b result is true <: $a < $b less than $a less than $ result true >: $a > $b greater than $ A greater than $b result is true <=: $a <= $b less than or equal to $ A $b result is true >=: $a >= $b greater than or equal to $ A or greater than or equal to $b result is true

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.