Skip to main content
Inspiring
October 6, 2007
Question

Formating to Percent

  • October 6, 2007
  • 3 replies
  • 354 views
I have a variable that is a long 0.1243453235 and I want to render it to a
percent. What function do I need to use?

And the darnest things is that I know this and cannot remember. :-)

--
Wally Kolcz
MyNextPet.org
Founder / Developer
586.871.4126


This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
October 6, 2007
<p>
<cfset x=0.26125513326308364>
<cfset xAsPercent = 100 * x>
x = <cfoutput>#x#</cfoutput><br>
x as percent = <cfoutput>#round(xAsPercent)#%</cfoutput><br>
</p>

<p>
<cfset y=0.26525513326308364>
<cfset yAsPercent = 100 * y>
y = <cfoutput>#y#</cfoutput><br>
y as percent = <cfoutput>#round(yAsPercent)#%</cfoutput>
</p>

Inspiring
October 6, 2007
That's close, but not exactly. I am getting:

Single Women 0.26%

How can I get it down to just 26%

The original number is: 0.26125513326308364


Participating Frequently
October 6, 2007
multiple results by 100 in a cfset statement

<cfset singlewomen=yourvar*100>

<cfoutput>#numberformat(singlewomen,"999")# %<cfoutput>

Participating Frequently
October 6, 2007
I use this:

<cfset teampercent=(spadesalt.win/spadesalt.total_games)*100>

then output

#numberformat(teampercent,"999.99")# %

But this is of course contingent upon what you are basing your percentage on