4 Replies Latest reply on May 26, 2013 2:41 AM by shilpa25

    How to get exact values.

    shilpa25 Level 1

      Hi Forum,

       

      I'm trying to get page margin Width and Height as a text in slug area.

       

      When I minus the pagewidh with pagemargin, i'm getting values in fractions like this.

       

      eg. 177.43999999.

       

       

      When i draw a rectangle box to check the width and Height, the measurement pallet show exactly like this.... 177.44

       

      How can i get exact values as i see in measurement pallette...

       

       

      var myTextFrame = myDocument.textFrames.add();

      with (myDocument.pages.item(0).marginPreferences){

                    //Save the current application default margin preferences.

          var myY1 = top;

                    var myX1 = left;

                    var myY2 = bottom;

                    var myX2 = right;

                    //Set the application default margin preferences.

                    var mWidth = parseFloat(myPageWidth - myX1 - myX2);

              var mHeight =  parseFloat(myPageHeight - myY2 - myY1);

         

        

                myTextFrame.contents = "Ratio: y = 1.75x – Artwork Final size = (H)" + myPageHeight + "mm x (W)" + myPageWidth +"mm  Artwork set at 25% of final size=(H)2410mm x (W)1370mm  Live area = (H)" + mHeight+ "mm x (W)" + mWidth+ "mm ";

                }

       

      thanks in advance for the help..

       

       

      thanks.

        • 1. Re: How to get exact values.
          Jump_Over Level 5

          Hi,

           

          you need to round this floats (i.e.):

           

          mWidth = Math.round(mWidth*100)/100;

           

          Jarek

          1 person found this helpful
          • 2. Re: How to get exact values.
            shilpa25 Level 1

            Hi Jarek,

             

            Many Many apologise for the delayed response.

             

            I fall in sick...

             

            Many thanks for your reply..

             

            I have a request to you... if I use Math.round it rounds ups the value...

             

            but, my request is to have the exact digits that is seen in Measurement tools. Wight and Height....

             

            eg. 23.457 in Width.... when using Math.round, i get as 23.5,

             

            I need to get the exact values 23.457...

             

            many thanks jarek..... much appreciated for your help....

            1 person found this helpful
            • 3. Re: How to get exact values.
              MrTIFF Level 3

              Math.round() always rounds to the nearest whole number (integer).  So Jarek's suggestion uses Math.round in a particular way ... he isn't rounding mWidth directly -- he is multiplying mWidth by 100, rounding the result to the nearest integer, and then dividing by 100. This gives you exactly 2 decimal places of accuracy.  If you want 1 decimal place, use 10 instead of 100.  If you want 3 decimal places, use 1000. 

               

              A general routine to round a floating point number to a particular number of decimal places is:

               

              // rounding to a give number of decimal places (tomaxxi)

              Number.prototype.doRound = function(roundDec){

                  var roundMulit = Math.pow(10,roundDec);

                  return Math.round(this*roundMulit)/roundMulit;

              };

               

              If you put the above code snippet at the beginning of your script, then in the main part of your script you can just do this:

               

              mWidth = mWidth.doRound( 3 ); 

               

              , if you want to round to at most 3 decimal places.

               

              Generally, you only want to do this in UI code, because there is a good chance that rounding the number (mWidth in this case) will LOSE precision, not GAIN precision, when you round to a certain number of decimal places. (Explaining exactly why this is true is a longer discussion.)

              • 4. Re: How to get exact values.
                shilpa25 Level 1

                Hi stephen0218

                 

                A great help from you, with indeed explanations. I accept the point (Explaining exactly why this is true is a longer discussion.).

                 

                Thanks so much, for what have you tuted in this discussion. Much appreciation to you..

                 

                 

                Jarek, thanks so much to you also...

                 

                thanks stephen0218 ji....

                 

                j,

                 

                Shil...