I have the following code:
<cfloop list="1|1.2|1,2|1,2,3" delimiters="|" index="x">
#X# - #int(x)# <br />
</cfloop>
Which produces this out开发者_如何学JAVAput:
1 - 1
1.2 - 1
1,2 - 40180
1,2,3 - 37623
What's happening when I pass in these lists?
INT() Behavior is undefined if you pass it something that is not a number.
You can check if a string is numeric with the isNumeric() function.
If you need to extract an number from an arbitrary string, use parseInt().
You'd better explain what results are expecting. Maybe you'll need int(val(x)) as workaround.
Consider this loop example to see the differences between functions you can use:
<cfloop list="1|1.2|1,2|1,2,3" delimiters="|" index="x">
#x# - #val(x)# - #int(val(x))# - #fix(val(x))# - #isNumeric(x)# - #isValid("integer", x)#<br />
</cfloop>
BTW, Railo makes this smarter: it throws an exeption when string can not be converted reliably (iterations 3 and 4).
加载中,请稍侯......
精彩评论