3 Replies Latest reply on Jun 29, 2015 6:25 AM by rickclark54

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

    rickclark54

      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>