Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!mordor!styx!ames!necntc!adelie!mirror!jvc From: jvc@mirror.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Rounding errors on a PC Message-ID: <206900027@mirror> Date: Fri, 24-Apr-87 09:26:00 EST Article-I.D.: mirror.206900027 Posted: Fri Apr 24 09:26:00 1987 Date-Received: Sat, 25-Apr-87 20:44:18 EST References: <979@ark.cs.vu.nl> Lines: 31 Nf-ID: #R:ark.cs.vu.nl:-97900:mirror:206900027:000:1415 Nf-From: mirror.UUCP!jvc Apr 24 09:26:00 1987 /* Written 10:21 am Apr 21, 1987 by huisjes@ark.UUCP in mirror:comp.sys.ibm.pc */ /* ---------- "Rounding errors on a PC" ---------- */ 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. /* End of text from mirror:comp.sys.ibm.pc */