如何使用Coldfusion格式化整数



我试图在整数上使用NumberFormat,以便用前导零填充它。不幸的是,NumberFormat似乎对整数没有影响。如有任何建议,我们将不胜感激。

 <cffunction name="myFunction" access="remote" returntype="numeric">
    <cfargument name="myId" type="numeric" required="yes" />
        <cfquery name="myQuery">
            SELECT COUNT(fileid) AS itemCount FROM files
            WHERE directory = '#myId#'
        </cfquery>
        <cfset newId = numberFormat( myQuery.itemCount, '0000000' )>
        <cfreturn newId />
</cffunction>

将返回类型更改为字符串。我确信numeric会截断前导零。此外,作为一种好的做法,将output="false"添加到所有的<cfcomponent><cffunction>标签中。

请改用Val()。

<cfset newId = Val(myQuery.itemCount)>

最新更新