search
Homephp教程php手册php FILTER_VALIDATE_FLOAT 浮点数验证

 

filter_validate_float 过滤器把值作为浮点数来验证。
*/
$var=12.3;

var_dump(filter_var($var, filter_validate_float));

//float(12.3)

/*
非负浮点数(正浮点数 + 0):^d+(.d+)?$
正浮点数   ^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$
非正浮点数(负浮点数 + 0) ^((-d+(.d+)?)|(0+(.0+)?))$
负浮点数  ^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$
浮点数  ^(-?d+)(.d+)?
更多详细内容请查看:http://www.bkjia.com/phper/php-function/35065.htm
在这里给大家介绍一种方法,它可以计算出以n成倍增加最接近float值的int值。说的不是很清楚,那就请大家直接看代码吧!


公式:round($number/n)*n
$number=1234.30;
$rounded = round($number / 3) * 3;
echo($rounded);
?>

结果:1233

1233可以整除3,且是整除3最接近1234.30。

 

这里提到round(),就顺便再介绍下它的常规用法,详细的日后将给予说明。


01.02.echo(round(3.1415927,2)."
");  
03.echo(round(1092,-2));  
04.?>  
echo(round(3.1415927,2)."
");
echo(round(1092,-2));
?> 

结果:

3.14
1100

 

round(3.1415927,2):保留2个小数,进行四舍五入。

round(1092,-2):将十位数四舍五入。

 

再顺便给大家介绍一个函数floor()。


01.02.echo floor(4.3);   // 4  
03.echo floor(9.999); // 9  
04.?>  
echo floor(4.3);   // 4
echo floor(9.999); // 9
?> 

返回不大于value的一个整数,将value的小数部分舍弃。这里需要注意下,虽然value被舍弃了小数部分,但是floor(value)得出的结果仍然是float。

*/
?>


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),