Copy link to clipboard
Copied
I ran the following code and it displayed my numbers correctly, ie: 1.75, 2.50:
<cfloop from="1" to="#getnumba#" index="idx">
<cfset getunit = form["unit" & idx]>
<cfoutput>#NumberFormat(getunit, "99.99")#</cfoutput><br />
</cfloop>
<cfabort>
But when I tried the following code, it rounded the numbers again:
<cfloop from="1" to="#getnumba#" index="idx">
<cfset getqty = form["qty" & idx]>
<cfset getitem = form["item" & idx]>
<cfset getunit = form["unit" & idx]>
<cfif (getqty is "") and (getitem is "") and (getunit is "")>
<cfset getqty = 0>
<cfset getitem = 0>
<cfset getunit = 0>
</cfif>
<cfquery name="insertItems" datasource="#application.dsn#">
INSERT into items
(orderID,
qty,
item,
unit
)
VALUES(
<cfqueryparam value="#getoid#" CFSQLType="CF_SQL_INTEGER" >,
<cfqueryparam value="#getqty#" CFSQLType="CF_SQL_INTEGER" >,
<cfqueryparam value="#getitem#" CFSQLType="CF_SQL_VARCHAR" >,
<cfqueryparam value="#NumberFormat(getunit, "99.99")#" CFSQLType="CF_SQL_INTEGER" >
)
</cfquery>
</cfloop>
Copy link to clipboard
Copied
Just a guess but in your cfqueryparam you are specifying CFSQLType="CF_SQL_INTEGER".
Copy link to clipboard
Copied
As mentioned by Steve, above, CF_SQL_INTEGER is causing the issue. Try CFSQLType="CF_SQL_DOUBLE" or CFSQLType="
CF_SQL_FLOAT", or
CF_SQL_NUMERIC
and CF_SQL_DECIMAL
. by adding the additional attribute, scale=1,2,3.... [scale => Number of decimal places you want passed in parameter. Applies to CF_SQL_NUMERIC
and CF_SQL_DECIMAL].
For example:
<cfqueryparam value="#NumberFormat(getunit, "99.99")#" CFSQLType="CF_SQL_DECIMAL" scale="2" >
Copy link to clipboard
Copied
Thank you gentlemen, the problem has been solved. I don't know why I wasn't notified of your responses.