coldfusion weird extra space

我的未来我决定 提交于 2019-12-01 17:12:52

Have you tried to added output="false" to your function tag?

<cffunction name="convertToNumber" returntype="numeric" output="false">...</cffunction>

Hope that helps.

I ran into a similar problem, and what worked for me was putting the value returned from the method into a variable and then outputting the variable instead of the return from the method. I didn't format it at all, but somehow that helped.

It's very simple. Put <cfsilent> in your <cffunction>. Need to put <cfsilent> after <cfargument>.

I've wrote about extra space within cffunction in my blog.

<cffunction name="convertToNumber" returntype="numeric">
    <cfargument name="separator" required="Yes" type="string" />
    <cfargument name="number" required="Yes" type="string" />
    <cfsilent>
        <cfset LOCAL.arrSeparator = ["comma", "period", "lakh_crore"] />
        <cfif ARGUMENTS.separator eq "comma" or ARGUMENTS.separator eq "lakh_crore">
            <cfif ListLen(ARGUMENTS.number, ".") eq 2>
                <cfset LOCAL.integral = ListFirst(ARGUMENTS.number, ".") />
                <cfset LOCAL.fractional = ListLast(ARGUMENTS.number, ".") />
            <cfelse>
                <cfset LOCAL.integral = ARGUMENTS.number />
                <cfset LOCAL.fractional = "" />
            </cfif>
            <cfset LOCAL.integral = Replace(LOCAL.integral, ",", "", "ALL") />
            <cfset LOCAL.returnValue = LOCAL.integral />
            <cfif Len(Trim(LOCAL.fractional))>
                <cfset LOCAL.returnValue &= "." & LOCAL.fractional />
            </cfif>
        </cfif>
        <cfif ARGUMENTS.separator eq "period">
            <cfif ListLen(ARGUMENTS.number, ",") eq 2>
                <cfset LOCAL.integral = ListFirst(ARGUMENTS.number, ",") />
                <cfset LOCAL.fractional = ListLast(ARGUMENTS.number, ",") />
            <cfelse>
                <cfset LOCAL.integral = ARGUMENTS.number />
                <cfset LOCAL.fractional = "" />
            </cfif>
            <cfset LOCAL.integral = Replace(LOCAL.integral, ".", "", "ALL") />
            <cfset LOCAL.returnValue = LOCAL.integral />
            <cfif Len(Trim(LOCAL.fractional))>
                <cfset LOCAL.returnValue &= "." & LOCAL.fractional />
            </cfif>
        </cfif>
        <cfreturn LOCAL.returnValue />
    </cfsilent>
</cffunction>

<cfset separatorNumber = StructNew() />
<cfset separatorNumber.comma = "1,234,567,890.123456" />
<cfset separatorNumber.period = "1.234.567.890,123456" />
<cfset separatorNumber.lakh_crore = "1,23,45,67,890.123456" />
<cfoutput>
    <cfloop collection="#separatorNumber#" item="separator">
        <p>
            #separator# : 
            <input type="Text" value="#convertToNumber(separator, separatorNumber[separator])#">
            Length : #Len(convertToNumber(separator, separatorNumber[separator]))# 
        </p>
    </cfloop>
</cfoutput>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!