Page 1 of 1
Numeric - float, rounding problem
Posted: 04.01.2012, 01:42
by boreas
Hi all,
I am using the zeos 922stable, Delphi XE, firebird 2.5.
I have a numeric (10.4) field. When recording in this field have already signed up some numbers wrong.
Example
Correct -> Wrong
1.95 -> 1.9444,
0.18 -> 0.1799
0.85 -> 0.8499
Is this a bug? What would you recommend me to do.
Thanks
Posted: 04.01.2012, 11:29
by papelhigienico
What's the field datatype?
Posted: 04.01.2012, 11:36
by boreas
Datatype float.
Posted: 04.01.2012, 12:26
by Wild_Pointer
hello,
are you sure you get the 1.95 -> 1.9444 ?? not 1.95 -> 1.9499 by chance?
Posted: 04.01.2012, 12:47
by boreas
i am sorry. yes 1.95 -> 1.9499
Posted: 04.01.2012, 13:23
by Wild_Pointer
the problem is due to the float representation 1.95 is in fact stored as 1.94999... The problem is that when writing it to DB it does not get rounded but truncated... I didn't notice that behavior on postgresql I'm working with so my guess is the problem is in interbase (firebird) part of zeos. Would you be able to find and fix it?
Posted: 04.01.2012, 13:34
by boreas
when i issue a direct command to DB via zsqlprocessor, there is no problem. I overcame this problem using this solution. However, I havent fount any other solution apart from this.
Posted: 04.01.2012, 13:48
by Wild_Pointer
Would you please try using BCD Fields instead Float fields?
Posted: 04.01.2012, 15:58
by boreas
thanks for the post.
as far I know, floating type is given by deplhi by default, I cannot change it. How may i convert it into BCD type?
I cannot use cast command, it doesnt allow me to modify (editing)
thanks in advance.
Posted: 05.01.2012, 08:36
by Wild_Pointer
hello
try deleting field and then adding it manually in the field list. When adding manually you can specify the field type. There is no way to convert a field from one type to another without recreating it. I'm not sure it will help (or work at all) but please experiment
Good luck!
Posted: 05.01.2012, 11:17
by papelhigienico
Float precision (32 bits). This issue happens on others databases, with variables, devices. Double datatype (64 bits) can solve this.
Posted: 05.01.2012, 11:58
by Wild_Pointer
hello papelhigienico,
but float(32) bit should have at least 7 digit precision. This is more than needed for the example. Please explain in more detail what goes wrong here please.
Thank you in advance
Posted: 05.01.2012, 14:30
by boreas
when i define the field manually, system does not allow anything but float. when i define it as float i enter any number i want, like 0,6000 and post it, however when i refresh it, it is displayed as 0,5999. And this is even not valid for every number. For example if I post 1,1450, i can do that. the number that is logged into the data base and the number I stored are not the same. All process regarding post and delete require to use zsqlprocessor.
I found no other alternatives.
Thanks
Posted: 06.01.2012, 02:54
by papelhigienico
Wild_Pointer, yes, I agree with this, but this don't occurs with some numbers... I don't know why.
Confirmation of a bug with this.
Posted: 10.01.2012, 12:26
by andrevanzuydam
I have a system that uses up to 10 decimals in some cases and this bug caught me.
The problem lies in UpdateBigDecimal in ZDBCInterbase6Utils
Please can you upload the code for your function so that I can see if I have a fix for it, It is possible that I have not made a commit for this fix.