Announcement

Collapse
No announcement yet.

How to round up

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to round up

    In working on my quizzing runtime I am running into a problem in trying to determine the maximum number of pages. What I am running into is fractional numbers being rounded down rather than up. Is there a way to force a number to round up rather than down?

    Here is what I am doing

    <font color=green>%MaxPageNum% = Evaluate (%NumFiles% / 4.0)</font color=green>

    This will divide the total number of questions by the maximum displayable per page. What is happening is that I have 10 questions that when divided by 4.0 gives me 2.5. If I divided by 4 it would give me 2, but I will actually have three pages. Is there an easy way to have it take the 2.5 and round up to 3?

    My thought on how to approach it was to parse the string grabbing the number before the "." and then check to see if the number returned was greater than the number before the ".". If it is, then I would add 1 to the number.

    Something like this
    <font color=green>%MaxPageNum% = Evaluate (%NumFiles% / 4.0)
    %NewString% = String.GetDelimitedString ("%MaxPageNum%", ".", 0)
    IF (%MaxPageNum% > %NewString%)
    %MaxPageNum% = Evaluate (%NewString% + 1)
    END IF</font color=green>

    But is there an easier way?
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  • #2
    Re: How to round up

    Just use Variable - Format Number, set it to either Round or Truncate as desired, and set the number of decimal places to 0.
    --[[ Indigo Rose Software Developer ]]

    Comment


    • #3
      Re: How to round up

      That would be ok for my current situation but I always want to round up.
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment


      • #4
        Re: How to round up

        In that case, just add 0.9999999 to the number and use the Format Number action to truncate the result.
        --[[ Indigo Rose Software Developer ]]

        Comment


        • #5
          Re: How to round up

          I figured there would be an easier way, I usually make things harder than they need to be. Oh well.

          Thanks
          TJ-Tigger
          "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
          "Draco dormiens nunquam titillandus."
          Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

          Comment


          • #6
            Re: How to round up

            If you ever anticipate having very large numbers (like, say you have a million questions [img]/ubbthreads/images/icons/smile.gif[/img]) you can calculate the exact number you need to make any fraction (within the set you will encounter) advance past the next integer. Just use:

            (total - 1) / total

            ...where "total" is the number you're dividing by. For example, in your case, there are 4 pages, so all you really need to add is 3/4, or .75, instead of .9999999.
            --[[ Indigo Rose Software Developer ]]

            Comment

            Working...
            X