Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com To: Marco Craveiro Cc: cygwin AT cygwin DOT com Subject: Re: atof returns a value that is slightly greater than the original string References: <1000153353 DOT 1101 DOT 8 DOT camel AT darkroom> From: Andrew Markebo Date: 10 Sep 2001 22:52:47 +0200 In-Reply-To: <1000153353.1101.8.camel@darkroom> Message-ID: Lines: 40 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii / Marco Craveiro wrote: | Hello Cygwinners, | | I'm having some strange problems with atof. basically, it returns a | converted value that is 0.000024 bigger than the one on the string. | | Google searching suggested that the problem was to do with #include | , but I already have that #include in my program and I still | get strange results. A program like this: | Same problem here if I do: #include #include int main (void) { float f=695.40; cout << f; } my gdb says f is 695.400024 If my mind doesn't fail me completely this is a 'misfeature' in float, the way that the data is stored in can't be exact.. or something.. The recommendations I have seen was to use some alternative bignum/smallnum package :-) Or if you know how many decimals you can get, multiply the value by that amount.. and convert to int. The reason to why you don't see it on cout is that cout prints floats with 1 or two decimals per default, if you tell it to print.. MANY decimals.. /Andy -- The eye of the beholder rests on the beauty! -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/