Does anyone know the reason why Adobe’s docs say `...
# cfml-general
f
Does anyone know the reason why Adobe’s docs say
Adobe recommends that you use the Floor function, instead of the Int function, in all new applications.
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-in-k/int.html ? Is there an actual reason or just that there are two functions doing the same thing?
got a PR in cfdocs to mark int as discouraged and I don’t want to do that if there is no real reason for it: https://github.com/foundeo/cfdocs/pull/1610
For some history CF had ceiling but not floor until CF2016, so you had to use int prior to that: https://www.petefreitag.com/item/634.cfm
b
I think it's just because that BIF name is more consistent
f
yeah - I get that, especially WRT other programming languages. But that being said most of the time I use the int function it is not because I want to floor a decimal, but rather as a way to assert that the variable is an integer. But I could just be weird like that, not sure if anyone else does that too.
b
I would bet the person who wrote that had some blinders on in regards to the scenarios they imagined it being used in 🙂
But I mean, floor() does technically ensure the input becomes an integer.
f
it always returns an integer or throws an exception
m
Is it because Floor has a hidden val() in it and int doesn't basically making floor(10.5) the same as int(val(10.5)) ?
f
I didn’t know that @Michael Gillespie that is handy
w
i think it was historically
fix()
wasn't it
f
I forgot about fix… is there a difference between fix and int?
w
i think fix was floor
to be used in lieu of, that is
m
@foundeo Yeah, I find a zero is easier to handle than a try/catch
👍 1
b
FWIW,
floor()
is NOT the same as
int(val())
Copy code
CFSCRIPT-REPL: int(val('3.5sdf'))
3
CFSCRIPT-REPL: floor('3.5sdf')
ERROR

can't cast [3.5sdf] string to a number value
val()
is a string function really, not a numeric one.
m
Well., so much for that idea..lol
<cfset x=int(val('10.5'))>
<cfset y=int(val('10.5xx'))>
<cfoutput>#x# - #y#</cfoutput>
10 - 10
b
I'm not sure what you're trying to show there
val() will truncate the string at the first non-numeric character it finds (exempting periods)
Floor, will error if the input is not parsable to a number
m
Sorry, I use this only when I have to use user provided data - should have included the test for Z
<cfset z=int(val('xx'))>
Straight up an example of "I know I do that somewhere, so I'll post without REALLY looking at it"
😁 1
b
I thought it had something to do with the treatment of negative numbers, but int & floor produce the same results. fix does differ from those two.