本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑php判断一个数有几位小数的方法方法1:借助strrpos()、substr()、strlen()函数<?php function getLen($nu
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php判断一个数有几位小数的方法
方法1:借助strrpos()、substr()、strlen()函数
<?php
function getLen($num)
{
$pos = strrpos($num, '.');
$ext = substr($num, $pos+1);
$len=strlen($ext);
return $len;
}
$num=3.14254;
echo getLen($num);
?>
输出结果:
5
方法2:借助explod()、array_pop()、strlen()函数
<?php
function getLen($num)
{
$arr = explode('.',$num);
$str=array_pop($arr);
$len=strlen($str);
return $len;
}
$num=25.365;
echo getLen($num);
?>
输出结果:
3
--结束END--
本文标题: php怎么判断有几位小数
本文链接: https://www.lsjlt.com/news/367.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-28
2023-09-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0