| |

VerySource

 Forgot password?
 Register
Search
Author: rosbicn

Simple and weird question about accuracy! !! !! Everyone help!

[Copy link]

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-28 17:15:01
| Show all posts
How to achieve s always display 8.07000000000000028? ? ? ? ? ?
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-7-28 18:15:01
| Show all posts
My knowledge is not professional enough, so I can only say an estimate:

I guess it is because the number of your # exceeds the accuracy range of real numbers. In fact, I estimate that 8.07 is displayed as 8.000000000000028, which is an error in itself. Please take a look at my reply above. The correct result should be displayed as 8.07 or 8.070000000000000

Then you press my code and replace var a: double; with var a: Extended; try, can you add a lot#
Reply

Use magic Report

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-28 22:00:01
| Show all posts
Thank you面面爱面面, but if I wish
var
  a:double;
  s:string;
  vADOConnection:Variant;
begin
  a := 8.07;
  s := formatfloat('#.################',a);//s display 8.07000000000000028
  vADOConnection := CreateOleObject('ADODB.Connection');
  vADOConnection.ConnectionString :='Driver={Firebird/InterBase(r) driver};pwd=masterkey;Uid=SYSDBA;database=C:\123.GDB';
  try
    vADOConnection.Open;
  Except
  end;
  a := 8.07;
  s := formatfloat('#.################',a);//s display 8.07
end;

The place where 8.07 is displayed also displays 8.07000000000000028, which means that even if it is wrong, it is also wrong!

I personally understand that vADOConnection.Open calls the MS library file, so the number after the effective digits is directly deleted. Is there any good way to not delete it?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list