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

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
Asked:
Mamea
3 Solutions
 
erikTsomikSystem Architect, CF programmer Commented:
the reson it return this because ceiling returns
smallest integer greater than or equal to a given number
0
 
erikTsomikSystem Architect, CF programmer Commented:
try using round
<cfoutput>#round(67*(75/100))#</cfoutput>
0
 
js_vaughanCommented:
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
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
erikTsomikSystem Architect, CF programmer Commented:
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
 
PluckaCommented:
Just change ceiling( to int(
0
 
gdemariaCommented:
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
 
js_vaughanCommented:
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
 
MameaAuthor Commented:
Thank you all for your help! I appreciate it!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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