tags:

views:

96

answers:

2

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 output:

1 - 1
1.2 - 1
1,2 - 40180
1,2,3 - 37623 

What's happening when I pass in these lists?

+5  A: 

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().

Byron Whitlock
+3  A: 

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).

Sergii
I actually wasn't expecting any particular result, I just happened upon the behavior by chance and was trying to determine how the output was being generated.
Anthony
guess it was some weird implementation carry over from legacy CF version...
Henry