Board index » delphi » Interesting problem wirh ROUND or FLOATTOSTR?????
morg...@primenet.com (G. Eric Morgan)
![]() Delphi Developer |
Fri, 13 Nov 1998 03:00:00 GMT
|
morg...@primenet.com (G. Eric Morgan)
![]() Delphi Developer |
Fri, 13 Nov 1998 03:00:00 GMT
Interesting problem wirh ROUND or FLOATTOSTR?????Create a form with 3 edit boxes and a button. Edit1 = float such as procedure TForm1.Button1Click(Sender: TObject); edit3 reads the following on my PC: 12.3459997177124 i.e. Round doesnt work or FloattoStr has floating point math error. Any Comments???? Eric |
G. Eric Morg
![]() Delphi Developer |
Fri, 13 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????On 27 May 1996 12:49:01 -0700, morg...@primenet.com (G. Eric Morgan) Actually, the problem is not with either function but when I divide Eric Quote>Create a form with 3 edit boxes and a button. Edit1 = float such as |
Duncan Murdo
![]() Delphi Developer |
Fri, 13 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????On 27 May 1996 12:49:01 -0700, morg...@primenet.com (G. Eric Morgan) Quote>Create a form with 3 edit boxes and a button. Edit1 = float such as and the result you got is correct to 6 or 7 digits. If you want more precision, use a bigger floating point type (i.e. double or extended). Duncan Murdoch |
G. Eric Morg
![]() Delphi Developer |
Fri, 13 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????On Mon, 27 May 1996 20:47:48 GMT, dmurd...@mast.queensu.ca (Duncan QuoteMurdoch) wrote: The result should be 12.346 even. I dont want more precision. I am trying to round the numbers. It is not Round or FloatToStr causing the problem. The problem is when I divide 12346 by 1000 I get 12.3459997177124. And I dont even have a Pentium!!! :) Any clues? Eric |
Svante Granqvis
![]() Delphi Developer |
Sat, 14 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????QuoteG. Eric Morgan wrote: 12.346-12.3459997177124=0.00000029 (approx), which is less than 1 in -- |
simon nichols
![]() Delphi Developer |
Sat, 14 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????morg...@primenet.com (G. Eric Morgan) wrote: Quote>Create a form with 3 edit boxes and a button. Edit1 = float such as Change your Single's to Extended and it'll work fine. I've had never Hope that helps, Simon. |
Richard MacDona
![]() Delphi Developer |
Sat, 14 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????On 27 May 1996 18:39:02 -0700, morg...@primenet.com (G. Eric Morgan) wrote: Quote>On Mon, 27 May 1996 20:47:48 GMT, dmurd...@mast.queensu.ca (Duncan accurately in base 2. That is most likely the source of the "error." You should be able to get the original number by rounding to 3 decimal positions. The only way to avoid such situations is to use fixed point arithmetic rather than floating point. Components are (or should be) available that can do fixed point arithmetic to dick |
Dmitry Streblechen
![]() Delphi Developer |
Sat, 14 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????Quote>It's not correct to 6 or 7 digits. Its not even correct to 3 digits. digits: you'll get 12.346000). Quote>The result should be 12.346 even. I dont want more precision. I am be represented exactly as a finite ratio in a decimal, it's an infinite ratio in a binary notation (which is used by your processor, even if it's not a faulty Pentium). Use FloatToStrF(Number,ffGeneral,8,8) - or something like that Dmitry |
Emmanuel Pirsc
![]() Delphi Developer |
Sun, 15 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????QuoteG. Eric Morgan wrote: Floating point numbers are represented in a BINARY form (not decimals)...= a number that can be represented precisly with a by a power of 10 may not= represented exactly with a power of 2... This is an old problem with any application that need really precise = result... The only overcome you can do is to use a larger precision type = then round it... Or is to build your own routine that do the calculation = a a decimal base ... The later will give a MUCH slower result... Even Supercomputer have the problem ;-) And this can give headache to = scientist who really need fast precise calculation in decimals... There is an article in Wired (somewhere in the Autumn '95) that is talkin= about the implication of that fact... Hope it help... -- = ---------- |
Ray Lischn
![]() Delphi Developer |
Sun, 15 Nov 1998 03:00:00 GMT
Re:Interesting problem wirh ROUND or FLOATTOSTR?????On 27 May 1996 12:49:01 -0700, morg...@primenet.com (G. Eric Morgan) Quote>Create a form with 3 edit boxes and a button. Edit1 = float such as about inexactness and floating point errors. Then look up the FloatToStrF function. |
1. Windows XP having problem wirh ADO Queries
2. Problems wirh TQuery: Insuficient Memory
3. Strange character problem wirh Paradox and BDE 5
4. Strange character problem wirh BDE 5.10
5. FloatToStr problems with formatted floats
6. MasterDetail-Relations wirh TIBDataset?