Solved

# Ceiling Tag

Posted on 2009-02-10
847 Views
Hi,

I inherited an application and I am looking at the following code that is calculating the number of questions you must answer correctly so you can pass the test.

#ceiling(getquestions.recordcount*request.passingpercent/100)#

request.passingpercent is always 75

for this example getquestions.recordcount is 67.

When you do the mathematical computation the answer is 50.25. Why is the tag rounding this up to 51? What I need to be displayed is 50 because if you have a test of 67 questions you have to answer 50 or more to pass (and passing is 75%).

Thanks

Thanks
0
Question by:Mamea

LVL 19

Assisted Solution

the reson it return this because ceiling returns
smallest integer greater than or equal to a given number
0

LVL 19

Expert Comment

try using round
<cfoutput>#round(67*(75/100))#</cfoutput>
0

LVL 10

Expert Comment

Ceiling() will always round up to the nearest whole number.  so even 50.01 will round up to 51.  If you want to always round down, use Int().  Use Round() to just round to the nearest whole number (either up or down)
0

LVL 19

Expert Comment

also you can read this
http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401292 but I think you better of with my above post
0

LVL 18

Expert Comment

Just change ceiling( to int(
0

LVL 39

Assisted Solution

but then again, 50 questions is less than 75%.  So maybe that's why the previous developer used ceiling.  That forces you to answer that one more question which will ensure it's 75% or a tad more, never less (like 74.5%)

Decide your business rules and then use round() to round up or down, ceiling() to always go up to the next question or int() to always drop the fraction and go down one less question
0

LVL 10

Accepted Solution

gdemaria is 100% correct.  here is why:

Plug in these numbers as an example:
request.passingpercent = 75
getquestions.recordcount = 7

Without Ceiling() :
getquestions.recordcount*request.passingpercent/100 = 7 * 75 / 100 = 5.25

If you replaced Ceiling() with Round(), this would incorrectly set the test to only require 5 answers to be correct.  5 out of 7 is only 71.42... percent; well below the passing score.  So Ceiling() will basically enforce the business rule that even a 74.99% correct will not pass.

Back to 50/67 = 74.63%  Im not sure about others, but in my school, a 74.63 would have never been rounded to a 75 either, so I would agree with gdemaria to consider your business rules.  Personally, I recommend keeping Ceiling().

Good catch gdemaria!
0

Author Closing Comment

Thank you all for your help! I appreciate it!
0

## Join & Write a Comment Already a member? Login.

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

#### 729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!