3 Replies Latest reply on Dec 22, 2010 5:30 PM by gkaiseril

    Numerical Rounding Issues....again

    RoC1909 Level 1

      Hey guys,

       

      I received some great help from "Try67" and "GKaiseril" in the past and with that help, I thought that I would have been able to make my form do what I want, but I am lost...again.

       

      To go over:

      I have a form that contains a table with many rows where the user can enter a number from 1 - 24 and I want it to round up to the nearest 1/4 hour (.15, .30, .45). I am using the code that Try67 posted and modified it for my use and for the most part, it works correctly except, for the following issues(below is the code):

       

      var x = this.rawValue
      var rounded_x = Math.floor(x);
      var new_x;

       

      // if (x-rounded_x<=0.125) new_x = rounded_x; // 0 - 0.125 round down to 0
      if (x-rounded_x<=0.15) new_x = rounded_x+0.15; // 0 - 0.15 round to 0.15
      else if (x-rounded_x<=0.30) new_x = rounded_x+0.30; // 0.16 - 0.30 round to 0.30
      else if (x-rounded_x<=0.45) new_x = rounded_x+0.45; // 0.31 - 0.45 round to 0.45
      else new_x = rounded_x+1; // 0.46 - .59 round up to 1

       

      First issue - When I open the form, the fields start out with .15 as a entry. How do I make the field have nothing in it until the user enters something? I know the line:

       

      if (x-rounded_x<=0.15) new_x = rounded_x+0.15; // 0 - 0.15 round to 0.15


      is the culprit to the intial rounding, but I cannot figure out how the syntax of the command would go. I would imagine it would be something like "from 0 to 0.001, round to 0. From .0011 to 15, round to 15".

       

      Second issue - How can I make it so that the field allows the user to ONLY enter a number UP TO 24 (corresponding to the hours in a day) and yet have the form round the number to the 1/4 hour correctly? i.e If I enter 24 into the field, it rounds it to 24.15 and I want 24 to be the largest amount that can be in the field.

       

      Hopefully I explained this correctly and thanks to all for helping me in the past.

        • 1. Re: Numerical Rounding Issues....again
          gkaiseril MVP & Adobe Community Professional

          Clear the form before saving the fied.

           

          Have you looked at the "Validation" tab?

          • 2. Re: Numerical Rounding Issues....again
            RoC1909 Level 1

            What I actually did was set a action that will pop up a message box if the field "is greater than" a set amount. I also created another action that would keep the focus set to the field if the first action was to happen, so that the user "will be prompted" to change the amount.

             

            I was also able to get the initial value to be "0" upon the form opening (not by clearing and saving the form as GKaiseril mentioned previously. This was due to my script rounding "0" up to .15), but that brings another problem. Since there are many fields in this form that need to have this calculation, I don't want the form to appear "crowded" with a bunch of "0" in the fields upon opening the form.

             

            Problem: Is there a way to have the fields display NOTHING if a amount has not been entered?

             

            and second...for these same fields as the problem stated above, I noticed that when a field is autmatically rounded to .30 as the nearest quarter hour, it doesn't show the "0", but only shows .3. Obviosuly, the other quarter hours won't have this problem. I also have the fields set up for 2 decimal places

             

            Problem: How can I make the a field display two decimal places (i.e.30) and not like it is now (i.e .3)?

             

            Thanks for all of your help.

            • 3. Re: Numerical Rounding Issues....again
              gkaiseril MVP & Adobe Community Professional

              It looks like your script should insert zero. I am not going to create a form and debug your script.

               

              You can try setting the field to a null character string. To display the wanted number of decimals, look at setting the number of decimals for a field with a numeric format or use the 'util.printf()" method.