Detailed explanation of digital functions in php

小云云
Release: 2023-03-22 15:16:02
Original
1806 people have browsed it

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(值)      向上取整
Copy after login

Power operation

pow(底数,指数)
Copy after login

Example

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

Square root

sqrt(数字)
Copy after login

Example

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

Random number

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

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

Number formatting

number_format(数字(,小数位数))
Copy after login

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;;
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template