Board index » delphi » Precision errors with Dbgrid in D5 with MSSQL 7 and BDE version 5.1

Precision errors with Dbgrid in D5 with MSSQL 7 and BDE version 5.1

Here's an interesting one.  In D5 create a simple form and add a dbgrid.
Link it to a table with numeric fields in an MSSQL 7 database .  Run the
program and enter the following number "99.99".  Now  move off  or save the
record.  The value will now show 99.9899.

Here are results using the same program with different combinations:

Keyed in:         Result after save:
9.99                        9.99
99.99                   99.9899  **
999.99                999.99
9999.99           9999.9899  **
99999.99        99999.99
999999.99    999999.9899  **

1.99                        1.99
12.99                    12.99
65.99                    65.9899  **
1234.99            1234.9899  **
4444.99            4444.9899  **

The precision of the tfloatfield is set to the default of 15.  The D5 help
says "Use Precision to set the number of digits beyond the decimal point
that the value should be formatted to before rounding begins. Precision
affects the format of the floating-point value when it is displayed as a
text string, not the actual floating-point value that is stored in the
field."

I interpret that to mean that precision indicates the number of digits to
the right of the decimal that will display (and not the total display
width).  Change the precision of the tfloatfield to a smaller number (say 4)
and you get the following results:

Keyed in:         Result after save:
9.99                        9.99
99.99                   99.99
999.99               1000
9999.99                IE4

Moving on... I can set the field value to 99.99 using MS Enterprise Manager
and the value is correct.  Pull it back up in Delphi and it is displayed
incorrectly.  It also saves the incorrect value in the database.

Lastly, change the currency flag to true and leave precision to it's default
of 15 and it all works fine.

Any comments or snide remarks on the cause?  Is this a bde bug, Delphi bug
or programmer ignorance?

Any work around suggestions?

Thanks,

Jerry C

P.S.  I did not try in older version of the BDE or Delphi.

 

Re:Precision errors with Dbgrid in D5 with MSSQL 7 and BDE version 5.1


That's a known problem with BDE, not with the server backside. I had to use BCD
for that reason (precision limited to 4).

Regards,

Alex Ehrlich

Quote
"J. Christin" wrote:
> Keyed in:         Result after save:
> 9.99                        9.99
> 99.99                   99.9899  **
> 999.99                999.99
> 9999.99           9999.9899  **
> 99999.99        99999.99
> 999999.99    999999.9899  **

Other Threads