title: How do I force a Coldfusion cfc to output numeric data over JSON as a string?
body: <p>I'm calling a Coldfusion component (cfc) using jQuery.post(). I need an integer or string representation of the number returned for use in a URL.</p>
  
  <pre><code>{"PAGE":"My Page Title","ID":19382}
  or
  {"PAGE":"My Page Title","ID":"19382"}
  </code></pre>
  
  <p>Instead what I get back is a decimal:</p>
  
  <pre><code>{"PAGE":"My Page Title","ID":19382.0}
  </code></pre>
  
  <p>Needed to update the following HTML:</p>
  
  <pre><code>&lt;a href="page.cfm?id=19382" id="pagelink"&gt;My Page Title&lt;/a&gt;
  </code></pre>
  
  <p>Conceptually, I suppose there are multiple answers:</p>
  
  <p>1) I could use jQuery to grab the number left of the decimal point.</p>
  
  <p>2) I could force Coldfusion to send the number as a string.</p>
  
  <p>3) I could generate the whole link server side and just replace the whole link tag HTML (not the preferred answer, but maybe it is the best)</p>
  
  <p>Does anyone know how to do 1 or 2? Is 3 better?</p>
  
  <p>Relevant Javascript: (Not optimized)</p>
  
  <pre><code>$(".link").live('click', function () {
      var $linkID, serviceUrl;
      serviceUrl = "mycfc.cfc?method=getPage";
      $linkID = $(this).attr("rel");
  
      $.post(serviceUrl, { linkid: $linkID }, function (result) { 
          $('#pagelink').val(result.TITLE);
          if (result.FMKEY.length) {
               // NEED the ID number WITHOUT the .0 at the end
               $('#pagelink').attr("href") = "page.cfm?id=" + result.ID;
               $('#pagelink').text(result.TITLE);
          }
      }, "json");
  });
  </code></pre>
  
  <p>My CFC:</p>
  
  <pre><code>&lt;component output="no"&gt;
  &lt;cfsetting showdebugoutput="no"&gt;
  &lt;cffunction name="getPage" access="remote" returnFormat="JSON" output="no" hint="Looks up a Page Title and ID"&gt;
      &lt;cfargument name="linkID" type="string" required="yes"&gt;
      &lt;cfset var page = queryNew("id,title")&gt;
      &lt;cfset var result = structNew()&gt;
      &lt;cfquery datasource="myDatasource" name="page"&gt;
          SELECT TOP 1 id, title
          FROM pages
          WHERE linkID = &lt;cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.linkID#"&gt;     
      &lt;/cfquery&gt;
      &lt;cfif page.recordcount&gt;
          &lt;cfset result.id = page.id&gt;
          &lt;cfset result.title = page.title&gt;
      &lt;/cfif&gt;
      &lt;cfreturn result&gt;
  &lt;/cffunction&gt;
  &lt;/component&gt;
  </code></pre>