Home > Back-end >  Delphi dbgrid data value type display decimal places
Delphi dbgrid data value type display decimal places

Time:10-15

Qry_in_storage_detail. FieldByName (' sum_weight). AsFloat:=Qry_in_storage_detail. FieldByName (' goods_weight '). AsFloat * Qry_in_storage_detail FieldByName (' goods_quantity). AsInteger;

Sum_weight defined in the database, goods_weight reserved for numeric eight decimal places, in the DBGRID goods_weight, however, suggests that there is no problem, but sum_weight calculated reserves eight decimal problems, such as goods_weight=0.21 goods_quantty=120, calculated results are: 25.19999999 rather than 25.20000000, please master to give directions, thank you

CodePudding user response:

Again, strange isn't it all records are wrong, some records is calculated the results

CodePudding user response:

Sum_weight goods_weight database is a numeric type, DELPHI Qry_in_storage_detail. FieldByName (' sum_weight). AsFloat:=Qry_in_storage_detail. FieldByName (' goods_weight '). AsFloat * Qry_in_storage_detail FieldByName (' goods_quantity). AsInteger; Asfloat is retained approximation, AsCurrency can only keep to four decimal places, excuse me how keep eight decimal places, and the calculation results are accurate

CodePudding user response:

Floating point types is such,
You should be displayed after using FormatFloat function to format,

CodePudding user response:

FormatFloat function can only be based on the content according to retain digits, now I want to keep eight decimal places, but it is because of the small digital was the result of 25.20000000, but showed a 25.19999999

CodePudding user response:

How to prepare the result, not display digits, the display would have no problem, is wrong

CodePudding user response:

Estimate your database using ACCESS, a data type of single precision number.
Changed to double, or decimal can solve this problem.

CodePudding user response:

I am using SQL

CodePudding user response:

SQL SERVER2008 data type to float, test the problem of the floating point precision,
Query as follows, operation * 120=25.2 0.21:
Select *, goods_weight * goods_quantity from table_b


CodePudding user response:

For example: FormatFloat (' 0.00000000 ', 22.22); Result was 22.22000000, don't know the building Lord said: FormatFloat function can only be based on the content according to retain what digits, still have even if, when you insert the data into the database, using FormatFloat set first digits, wrote enters sells saves, said there was no such calculation error,
  • Related