I just want to point out an issue with isValid(“integer”, someValue) when someValue is money that you converted to cents by multiplying 100.
Here’s an example:
money = 17.10;
cents = JavaCast("integer", money * 100);
writeOutput( "<p>isValid('integer', #cents#) = #isValid('integer', cents)#</p>");
isValid(‘integer’, 1710) = false
money = 17.25;
cents = JavaCast("integer", money * 100);
writeOutput( "<p>isValid('integer', #cents#) = #isValid('integer', cents)#</p>");
isValid(‘integer’, 1725) = true
I should note that this behavior appears to occur on both Lucee and ACF. I submitted a Lucee bug report here: [LDEV-3926] - Lucee
I ran into this problem when using the Stripe-CFML library and noticed an intermittent exception that occurred when testing. I created an issue here.
My workaround is to call JavaCast(“integer” cents);
as per the banner in jira, please always wait for feedback from your mailing list post before filing a bug
this seems to be working as expected?
@Zackster @Redtopia This is not an issue with isValid()
, it’s just a floating point math error. Look at this example:
dump( isValid("integer", 17.10*100) )
dump( 17.10*100 )
dump( (17.10*100).toString() )
The output is:
boolean false
number 1710
string 1710.0000000000002
As you can see, the result is NOT an integer behind the scenes even though Lucee rounds it to one on output.
Sorry… that’s I had already filled out the ticket before seeing that.
I figured it was an issue with the data type starting out as a float, but given the math I am executing, it didn’t seem like there should be any floating point issues, and isValid(“integer”, cents) should work. Thanks for clarifying @bdw429s.
Floating point maths is always a cluster fuck!
The ticket for the floating point arithmetic operations issue in Jira
https://luceeserver.atlassian.net/browse/LDEV-646