|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Grouping Floats
I'm having some problems with floats atm.
I have a table where I store all material movements inside a company, where I store unit prices, quantities and discounts. I then make some reports using delphi 5. The problem is that something is happening with the grouping / rounding of the values. Let me post an example. Imagine that the following values where entered (the exact values): 100 units of material A, unit price = 0,95, discount = 54% Now when I make the report I do get, in most of the times, the correct values: Quant=100; Price=0,95 €; Discount = 54%; Total=43,70 € Unfortunately, sometimes I do get a different return: Quant=100; Price=0,96 €; Discount = 54%; Total=44,16 € Now, can someone give me some hint about the possible cause? Is it because of float type (hence changing it do decimal could solve it), or is the origin within delphi (masks, roundings or use of extended type)? Thank you all in advance, Bruno Nunes |
|
#2
|
||||
|
||||
|
Quote:
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
|
#3
|
|||
|
|||
|
You're obviously correct...
Still having some trouble diagnosing it though, as it seldom returns the incorrect value... Will keep testing both the query and the report, both on a float field table and a decimal field table. |
|
#4
|
|||
|
|||
|
Quote:
You say you will post an example; but I do not see the SQL Can you post it? Typically, these problems surface when the rounding is done too early in the process. Illustration: Wrong: Sum(Round(Value)) Right: Round(Sum(Value)) Clive. |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Grouping Floats |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|