Thursday, March 19, 2009

cfqueryparam cf_sql_decimal scale default

A few months ago I was debugging some code that was rounding to the nearest int even though the data being entered was of decimal type. I checked the code to see if round() or numberformat() was being used, but they weren't. I started throwing dumps in the cfquery and noticed that before the decimal var entered in the cfqueryparam it was a decimal, but when the query was ran it was of type int. I was totally confused on how the number was being formatted. Turns out there is a scale attribute I was unaware of on cfqueryparam. The scale attribute is defaulted to 0 and is only applicable to cf_sql_numeric and cf_sql_decimal. I think it's kinda pointless for cf_sql_decimal to have zero decimals. Anyways I ended up adding scale to cfqueryparam with a value of 2 and fixed the issue.

I can see why scale of zero would make sense for cf_sql_numeric but not for cf_sql_decimal.

No comments:

Post a Comment