#X# - #int(x)#

What does int (x) really do?

I have the following code:

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

What produces this conclusion:

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

What happens when I go to these lists?

+3
source share
2 answers

INT() The behavior is undefined if you pass it something that is not a number.

You can check if a string is numeric using a function isNumeric().

If you need to extract a number from an arbitrary string, use parseInt().

+5
source

Better explain what results are expected. You might need it int(val(x))as a workaround.

Consider this example loop to see the differences between the 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 : , ( 3 4).

+3

Source: https://habr.com/ru/post/1753781/


All Articles