Coldfusion cfqueryparam of type decimal, cf_sql_decimal, requires the scale argument

I learned the hard way that if you don’t include the scale attribute in the cf_sql_decimal cfqueryparam tag, then your decimal gets rounded to the nearest whole number. IF this isn’t what is intended, this can really bite. Make sure you specify the scale with the scale argument to make you cfqueryparam as accurate as intended.

<cfqueryparam cfsqltype="cf_sql_decimal" scale="8" value="#decimalvar# />

WRONG (Unless whole numbers desired):

<cfqueryparam cfsqltype="cf_sql_decimal" value="#decimalvar# />

Leave a Reply

Your email address will not be published. Required fields are marked *