什么是int(x)真的在做什么?

Ant*_*ony 3 coldfusion

我有以下代码:

<cfloop list="1|1.2|1,2|1,2,3" delimiters="|" index="x">
    #X# - #int(x)# <br />
</cfloop>
Run Code Online (Sandbox Code Playgroud)

哪个产生这个输出:

1 - 1
1.2 - 1
1,2 - 40180
1,2,3 - 37623 
Run Code Online (Sandbox Code Playgroud)

当我通过这些名单时发生了什么?

Byr*_*ock 5

INT() 如果您传递的内容不是数字,则行为未定义.

您可以使用该isNumeric()函数检查字符串是否为数字.

如果需要从任意字符串中提取数字,请使用parseInt().