开发者

In Coldfusion / CFML, how do you format a long decimal number to a standard two number percentage?

开发者 https://www.devze.com 2022-12-13 15:12 出处:网络
In Coldfusion / CFML I need to convert 0.85035035035 to 85%. I开发者_运维问答 looked at numberFormat(), but it\'s output looks like, \"0.85\". There doesn\'t seem to have a method to omit the leading

In Coldfusion / CFML I need to convert 0.85035035035 to 85%. I开发者_运维问答 looked at numberFormat(), but it's output looks like, "0.85". There doesn't seem to have a method to omit the leading "0.".

<cfset myNumber = 0.85035035035>
<cfoutput>
    #numberFormat(myNumber, "0.00")#%
</cfoutput>

Outputs: 0.85%

Ideas? Do I need to trim the leading 2 characters in a second operation?

<cfset myNumber = 0.85035035035>
<cfset myPercent = numberFormat(myNumber, "0.00")>
<cfoutput>
    #right(myPercent, 2)# %
</cfoutput>


<cfoutput>#Round(myNumber * 100)#%</cfoutput>


 <cfset num = 0.85>
 <cfoutput>#NumberFormat(num * 100,"999")#%</cfoutput>
0

精彩评论

暂无评论...
验证码 换一张
取 消