7 Replies Latest reply on May 13, 2012 3:05 AM by Peter Kahrel

    JS: toPrecision()

    Peter Kahrel Adobe Community Professional & MVP

      I used to think that to Number.toPrecision(d) set the number of decimal places (and the OMV help confirms that) so that, for instance,

       

      n = 12.34567

      n.toPrecision (2)

       

      would return 123.45. But it doesn't: it returns 12. n.toPrecision(4) returns 12.34. In fact, it looks as if toPrecision now works like a kind of slice():

       

      n = 12.34567

      n.toPrecision (4)

       

      returns 12.35: it removes the decimal point, takes the first four digits, rounds up.

       

      Clearly there's something I miss. But what?

       

      Thanks,

       

      Peter