• Status: Solved
• Priority: Medium
• Security: Public
• Views: 859

# Ceiling Tag

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
Mamea
3 Solutions

System Architect, CF programmer Commented:
the reson it return this because ceiling returns
smallest integer greater than or equal to a given number
0

System Architect, CF programmer Commented:
try using round
<cfoutput>#round(67*(75/100))#</cfoutput>
0

Commented:
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

System Architect, CF programmer Commented:
http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401292 but I think you better of with my above post
0

Commented:
Just change ceiling( to int(
0

Commented:
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

Commented:
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 Commented:
Thank you all for your help! I appreciate it!
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.