• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I use cfloop to insert numbers that are not rounded?

New Here ,
Jun 24, 2015 Jun 24, 2015

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>

Views

262

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 24, 2015 Jun 24, 2015

Copy link to clipboard

Copied

Just a guess but in your cfqueryparam you are specifying CFSQLType="CF_SQL_INTEGER".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2015 Jun 24, 2015

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" >

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2015 Jun 29, 2015

Copy link to clipboard

Copied

LATEST

Thank you gentlemen, the problem has been solved. I don't know why I wasn't notified of your responses.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation