Professional Web Applications Themes

Displaying as a percentage - Macromedia ColdFusion

In my SQL Query I am selecting two fields from an Access database, both of which are numbers. I am then dividing the two together and using AS to create a new virtual field. The new "Percentages" field is showing the correct answer but the answer is in decimals (i.e. .666666) and I need it to be formateed as a percentage (i.e. 67%). Is there a way to do this in ColdFusion? Part of my SELECT statement is below; Evaluations.Total_Points/QuestionSet1.A_Answer_Points AS Percentages (i.e. 4/6+.666666666) Is there a way to refernce the variable #Percentages# and have it displayed as a percentage? ...

  1. #1

    Default Displaying as a percentage

    In my SQL Query I am selecting two fields from an Access database, both of
    which are numbers. I am then dividing the two together and using AS to create a
    new virtual field. The new "Percentages" field is showing the correct answer
    but the answer is in decimals (i.e. .666666) and I need it to be formateed as a
    percentage (i.e. 67%). Is there a way to do this in ColdFusion? Part of my
    SELECT statement is below;

    Evaluations.Total_Points/QuestionSet1.A_Answer_Points AS Percentages (i.e.
    4/6+.666666666)

    Is there a way to refernce the variable #Percentages# and have it displayed as
    a percentage?

    Thanks for your help


    AHT Barry Guest

  2. #2

    Default Re: Displaying as a percentage

    Yes, you can do calculations and formatting on #Percentages#.
    Something like "#Round (Percentages * 100.0)#%" would work. BUT...

    You may be able to do this much more elegantly in Access.

    Try changing that select snippit to:
    SELECT Format (Evaluations.Total_Points/QuestionSet1.A_Answer_Points, "0%") AS
    Percentages

    Regards,
    -- MikeR


    MikerRoo Guest

  3. #3

    Default Re: Displaying as a percentage

    Minor correction to the last post.

    Round() will work perfectly, if you are interested in whole percents. If you
    may (or want) to have something like: 3.5%, the NumberFormat() is more
    appropriate. NumberFormat() also does requested rounding for you. For example:

    NumberFormat(num*100, "___._") - percent with one decimal.



    Mr Black Guest

  4. #4

    Default Re: Displaying as a percentage

    Mr Black's right if you want to futz around with formatting after the fact.
    NumberFormat() is better than Round() from a code flexibility standpoint.

    However, NumberFormat() isn't half as powerful as Access' Format() function.
    (Format() formats %, for example, NumberFormat() doesn't).

    My point was it is better to format the data the way you want it at the
    beginning (the database), than to clean it up later.
    Cleaning it up later, costs more code and more processing time.

    -- MikeR


    MikerRoo Guest

  5. #5

    Default Re: Displaying as a percentage

    Thanks for the help guys. I tried to use the suggestion for formatting it in
    Access but kept getting a "missing parameter" error. I did howver get it to
    work using the NumberFormat() tag in ColdFusion and it is worknig perfectly!

    Thanks again.

    AHT Barry Guest

  6. #6

    Default Re: Displaying as a percentage

    You got that missing parameter error because of the way CF handles quotes for Access. My bad.
    Change "0%" to '0%' (single quotes) and it will work.

    -- MikeR
    MikerRoo Guest

Similar Threads

  1. FLVPlayback Percentage Buffered Possible?
    By bigtart in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: November 13th, 06:24 PM
  2. CFCharts and Percentage
    By Rafael Klawonn in forum Macromedia ColdFusion
    Replies: 0
    Last Post: February 18th, 10:37 AM
  3. Getting an accurate Tax percentage
    By Laphan in forum ASP Database
    Replies: 1
    Last Post: July 28th, 11:29 AM
  4. Percentage of original size
    By Stephen_Hawk@adobeforums.com in forum Adobe Indesign Windows
    Replies: 3
    Last Post: April 13th, 08:00 PM
  5. preloader percentage
    By moni_80 in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: February 11th, 12:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139