On Tue, Oct 22, 2002 at 11:15:02AM -0700, naveen prabhakar wrote: > > Hi, > > I have a really simple question.I have two numbers > > say $a = 1.559999 > > $b=1.5599999999 > > how do I compare them to exactly 6 decimals without doing a round > off.I used sprintf but it does a round off. > > thank you.
You should always be very careful comparing numbers which may not be accurately represented. In Perl, as with most programming languages, this includes floating point numbers. Any method which involves comparing the numbers as strings is probably not to be recommended, even though it will probably work up to six decimal places. The standard approach to comparing for equality is to subtract one number from the other and check that the absolute value of the result is less than some threshold. Perhaps this approach will work for you. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]