如何检查字符串是否为浮点数? [英] How can I check if a string is a float?
本文介绍了如何检查字符串是否为浮点数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我传入一个名为value的参数。我想知道价值是否是浮动。
到目前为止,我有以下内容:
I am passing in a parameter called value. I'd like to know if value is a float. So far, I have the following:
if (!isNaN(value))
{
alert('this is a numeric value but not sure if it is a float.');
}
如何更进一步将字符串转换为可以评估的字符串到浮动?
How do I go one step further and convert the string to something that can evaluate to a float?
推荐答案
像这样:
if (!isNaN(value) && value.toString().indexOf('.') != -1)
{
alert('this is a numeric value and I\'m sure it is a float.');
}
这篇关于如何检查字符串是否为浮点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文