Nick Ing-Simmons wrote: > But: > > perl -e "print sprintf('%.20f', '1.045')" > 1.04499999999999992895 > > The boundary is drawn an 5 in next digit down so that falls under it. > I don't know if you should necessarily draw that conclusion. There no generic way to know when the actual binary representation is inexact (like it is in this case). In any case, your code is subtly different, since you are passing a string, which Perl then converts to a number. There is frequently a difference between an asserted and a calculated floating point number. The moral of the story is when using floating point numbers and requiring significant accuracy, Math:::BigFloat is a much better choice than any general floating point library. John -- John Peacock Director of Information Research and Technology Rowman & Littlefield Publishing Group 4720 Boston Way Lanham, MD 20706 301-459-3366 x.5010 fax 301-429-5747Thread Previous | Thread Next