1 Reply Latest reply on May 6, 2010 8:56 AM by gkaiseril

    Adobe Forms: math.round / multipication bug in  / java script

    Softare-Management GmbH

       

       

       

      Dear Forum / Dear Adobe Team,

       

      there is a critial bug in the multiplication operation. The problem is that this problem occurs in all latest Adobe Reader Editions and Adobe Acrobat Editions.

       

      See this code as an example

      var f= 367.295;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
      var f= 567.295;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
      var f= 567.285;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
      var f= 567.275;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
      var f= 567.265;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
      var f= 567.245;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);

      result:

      input:367.295 * 100 result in:36729.5
      input:567.295 * 100 result in:56729.49999999999 //>>>>>> bug and causes critical round erros
      input:567.285 * 100 result in:56728.5
      input:567.275 * 100 result in:56727.5
      input:567.265 * 100 result in:56726.5
      input:567.245 * 100 result in:56724.5

       

      Thank you for your support

      Software-Management GmbH

        • 1. Re: Adobe Forms: math.round / multiplication bug in  / java script
          gkaiseril MVP & Adobe Community Professional

          Nothing new, same thing occurs with version 8. You can write and use a rounding function.

           

          console.println('Type: ' + app.viewerType);
          console.println('Variation: ' + app.viewerVariation);
          console.println('Version: ' + app.viewerVersion);
          console.println('');

           

          function Round(nValue, iDecimal) {
          iDecimal = Math.floor(iDecimal); // make integer
          var nAdjustment = Math.pow(10, iDecimal); // power of 10 for decimal adjustment
          var nAdjusted = nValue * nAdjustment; // adjust value for rounding
          var nRounded = Math.round(nAdjusted); // round
          var nRounded = nRounded / nAdjustment; // move decimal back
          return nRounded; // return rounded value
          }

           

          var f= 367.295;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
          var f= 567.295;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
          var f= 567.285;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
          var f= 567.275;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
          var f= 567.265;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);
          var f= 567.245;  var dest=f*100; console.println("input:"+f+ " * 100 result in:"+ dest);

          // using Round function
          console.println('')
          console.println('using Round() function:');
          var f = 367.295;  var dest = Round(f*100, 1); console.println("input:"+f+ " * 100 result in:"+ dest);
          var f = 567.295;  var dest = Round(f*100, 1); console.println("input:"+f+ " * 100 result in:"+ dest);
          var f = 567.285;  var dest = Round(f*100, 1); console.println("input:"+f+ " * 100 result in:"+ dest);
          var f = 567.275;  var dest = Round(f*100, 1); console.println("input:"+f+ " * 100 result in:"+ dest);
          var f = 567.265;  var dest = Round(f*100, 1); console.println("input:"+f+ " * 100 result in:"+ dest);
          var f = 567.245;  var dest = Round(f*100, 1); console.println("input:"+f+ " * 100 result in:"+ dest);

           

          Type: Exchange-Pro
          Variation: Full
          Version: 8.101

          input:367.295 * 100 result in:36729.5
          input:567.295 * 100 result in:56729.49999999999
          input:567.285 * 100 result in:56728.5
          input:567.275 * 100 result in:56727.5
          input:567.265 * 100 result in:56726.5
          input:567.245 * 100 result in:56724.5

           

          using Round() function:
          input:367.295 * 100 result in:36729.5
          input:567.295 * 100 result in:56729.5
          input:567.285 * 100 result in:56728.5
          input:567.275 * 100 result in:56727.5
          input:567.265 * 100 result in:56726.5
          input:567.245 * 100 result in:56724.5

           

          true

           

          This is a problem anytime decimal are stored as a binary value. It is also a known issue with JavaScirpt. Multiplication and division results really produce this problem.

           

          Have you tired additon like  0.06 + 0.01?

          Have you tried subtraction like 0.07 - 0.01?