检查值是否为整数的最佳方法? Coldfusion 9 [英] Best way to check if value is integer ? Coldfusion 9

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

问题描述

我有要测试的字段,请确保它们仅接受integers.功能很少,但是我不确定哪个是最好的.首先,我尝试了isValid("integer",value),但是我发现"1,5"将被接受为整数.因此,我尝试了isNumeric(value),但这将接受1.5之类的值.我想知道什么是检查整数的最佳方法?也许两个结合了这两个功能,如:

I have fields to test and make sure they only accept integers. There is few functions but I wasn't sure which one is the best. First I tried isValid("integer",value) but I have discovered that "1,5" will be accepted as an integer. So then I tried isNumeric(value) but this will accept values like 1.5. I'm wondering what should be the best way to check for integers? Maybe two combine these two functions like:

<cfif isValid("integer",value) AND isNumeric(value)>

还是有更好的方法呢?

推荐答案

您可以尝试以下方法:

value = replace(value, ',', '', 'all');
numberIsInteger = isNumeric(value) && round(value) == value ? true : false;

注意 人们通常包括大量逗号,例如1,000,000. isNumeric将对该字符串返回false,其他答案中的refind函数也将返回.

Note People often include commas in large numbers such as 1,000,000. isNumeric will return false for that string, as will the refind function in the other answers.

这篇关于检查值是否为整数的最佳方法? Coldfusion 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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