Skip to main content
Inspiring
February 8, 2010
Question

How to calucate percentage

  • February 8, 2010
  • 3 replies
  • 3257 views

I need a formula to calculate a total percent of goal so far.

So here is the problem;

The Goal to collect is:  $2,300.00
So far this amount has been donated: $350.00

I want to show to the user the percentage so far collected, the image that I will show will have a 0% to 100% graph .  Any thoughts on how to do the calculation.

Thanks

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    February 8, 2010

    <!--- percentage to decimal accuracy --->
    <!--- <cfset percentCollected = 100*350/2300>
    <cfset percentDue = 100*1950/2300> --->

    <!--- rounded percentage --->
    <cfset percentCollected = round(100*350/2300)>
    <cfset percentDue = round(100*1950/2300)>

    <!--- pie chart (as image or flash) --->
    <cfchart format="png"> 
    <!--- <cfchart format="flash">  --->
    <cfchartseries type="pie">
    <cfchartdata item="Collected" value="#percentCollected#">
        <cfchartdata item="Due" value="#percentDue#">
    </cfchartseries>
    </cfchart>

    Participating Frequently
    February 8, 2010

    You can use cfchart to do this.  Here are a few tutorials on its use http://www.quackit.com/coldfusion/tutorial/coldfusion_charts.cfm

    Or just use jquery, as really you don't need ColdFusion to do this necessarily.

    http://xaviershay.github.com/tufte-graph/

    ilssac
    Inspiring
    February 8, 2010

    <cfoutput>#(350/2300)*100#</cfoutput>

    That is the usual mathmetical way to calculate a percentateg.

    How you plan to display that may be another issue.