检查数字是否是小数 [英] Check if number is decimal

查看:94
本文介绍了检查数字是否是小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户输入了一个十进制数字(US方式,带小数点:X.XXX),我需要检查PHP。

任何可靠的方法来执行此操作?

解决方案

你可以从 is_float ,但是如果你真的需要知道它是否有小数,你上面的函数并不是非常远(尽管是错误的语言):

$ p $ 函数is_decimal($ val)
{
return is_numeric($ val)&&楼($ val)!= $ val;
}


I need to check in PHP if user entered a decimal number (US way, with decimal point: X.XXX)

Any reliable way to do this?

解决方案

You can get most of what you want from is_float, but if you really need to know whether it has a decimal in it, your function above isn't terribly far (albeit the wrong language):

function is_decimal( $val )
{
    return is_numeric( $val ) && floor( $val ) != $val;
}

这篇关于检查数字是否是小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆