Home  >  Article  >  Backend Development  >  Detailed explanation of digital functions in php

Detailed explanation of digital functions in php

小云云
小云云Original
2018-03-29 09:07:561807browse

This article mainly shares with you the detailed explanation of PHP's digital functions. It mainly explains it in the form of code. I hope it can help you.

Rounding

floor(值)     向下取整

ceil(值)      向上取整

Power operation

pow(底数,指数)

Example

// 输出2的3次方
echo pow(2,3);   // 8

Square root

sqrt(数字)

Example

//输出4的平方根
echo sqrt(4);  // 2

Random number

rand(start,end)      比较慢,而且有

mt_rand(start,end)   推荐使用,性能好

Number formatting

number_format(数字(,小数位数))

If only numbers are passed in, decimals will not be retained and ## will be added to the thousands place. #, are used as delimiters.

Example

// 格式化
$x = 6789.123;

echo number_format($x);   // 6,789
echo &#39;<br/>&#39;;
echo number_format($x,2); // 6,789.12
echo &#39;<hr/>&#39;;

Related recommendations:


5. Single-line functions, multi-line functions, character functions, numeric functions, Date function, data type

The above is the detailed content of Detailed explanation of digital functions in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn