The processing of numeric types in PHP is: Ceil floor round intval sprintf Number_format

Source: Internet
Author: User
Tags rtrim sprintf

1<?PHP2 //ceil-into one method to take the whole3 //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 () Example4 Echo Ceil(4.3);//55 Echo Ceil(9.999);//Ten6 7 //floor-and rounding out the whole process8 //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. 9 Echo  Floor(4.3);//4Ten Echo  Floor(9.999);//9 One  A //round-rounding of floating-point numbers - //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).  - Echo round(3.4);//3 the Echo round(3.5);//4 - Echo round(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 A  at //intval-the variable into integer form - Echo intval(4.3);//4 - Echo intval(4.6);//4 -  - //sprintf with RTrim when preserving two decimal places remove end 0 - $float=sprintf('%.2f ', 2.99851);//3.00 in $nonezero=RTrim($float, 0);//3. - $number=RTrim($nonezero,‘.‘);//3 to /*trim strips the left and right spaces of the string to specify the removal of the specified word such as trim (' Hello world! ', '! ') will return ' Hello World ', the same ltrim remove the left null character or the specified character, RTrim remove the right blank character or the specified character*/ +  - //Number_format (number,decimals,decimalpoint,separator) formatting numbers the //decimals is optional. How many decimal places are specified. If this parameter is set, the number is formatted with a dot (.) as the decimal point.  * //decimalpoint is optional. Specifies a string to use as a decimal point.  $ //separator is optional. Specifies the string to use as the thousand separator. Only the first character of the parameter is used. For example, "XYZ" only outputs "X". Note: If this parameter is set, all other parameters are required. Panax Notoginseng $number= ' 123456.7890 '; - Echo Number_format($number).‘ <br/> ';//123,457 the Echo Number_format($number,NULL,NULL,‘ ‘).‘ <br/> ';//123 457 + Echo Number_format($number, 2, '. ', '). ' <br/> ';//123456.79 A Echo Number_format($number, 2, ".", ","). ' <br/> ';//1234,567.79

The

Processing of numeric types in PHP is: Ceil floor round intval sprintf Number_format

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.