Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!botter!ark!huisjes From: huisjes@ark.cs.vu.nl (Michiel Huisjes) Newsgroups: comp.sys.ibm.pc Subject: Rounding errors on a PC Message-ID: <979@ark.cs.vu.nl> Date: Tue, 21-Apr-87 10:21:08 EST Article-I.D.: ark.979 Posted: Tue Apr 21 10:21:08 1987 Date-Received: Wed, 22-Apr-87 04:29:21 EST Reply-To: huisjes@cs.vu.nl (Michiel Huisjes) Distribution: world Organization: VU Informatica, Amsterdam Lines: 27 We are developing an administration package for IBM PC and compatibles, using the Microsoft C compiler 4.00 and no 8087 co-processor. When we entered the number "123456.01" and printing it afterwards, we got "123456.09999999" back. Using this float in calculations leads (very quickly) to a rounding error of one (or more) cents. Although this amount of money, isn't that much to loose, it shouldn't happen in an administration package. Is this a compiler error, or just the inaccuracy of an IBM PC? If the latter is the case, what can be done about it. I know that the COBOL compiler uses BCD (Binary Coded Decimals) for its calculations, but implementing this in C, would mean writing all substraction, addition, multiplication, etc. routines all over. Do such packages already exist? Is there an undocumented obscure C compiler flag I don't know about? Has anybody out there encountered the same problem and if so, how did they deal with it? Answers to these questions or solutions are VERY welcome. If any useful solutions are presented, or wise remarks are made, I will summarize to the net. Please send replies to: Michiel Huisjes. (huisjes@cs.vu.nl) {seismo|decvax|philabs}!mcvax!vu44!huisjes Thanx in advance.