Page 1 of 1

Money field problem

Posted: 06.06.2010, 18:09
by aozbeyaz
Hi all,

I am new in forum. I have a question.

I use postgresql for my database application and I use Delphi 7 for programming. In delphi, I use Zeos6.6.6 components to connect to postgresql from delphi.

All values in money fields in postgresql table come to dbgrid as 0(zero) values. Namely, real values in money fields don't come to ZTable or ZQuery as real in Delphi.

if you help me, I will be able to happy.

thanks :)

Posted: 08.06.2010, 07:42
by seawolf
Aparte the fact money field is deprecated, I suppose there are data saved on this field. But are this data different from 0? Becusase I'm trying to insert some data in a money field with pgAdmin,but I can't insert their. Which Postgres version are you using?

Posted: 09.06.2010, 14:56
by aozbeyaz
I use Postgresql 8.4

Posted: 23.02.2012, 22:30
by sfxcc
Any solution with this , i can add it on pgadmin or even on the grid but it show 0 , which means grid can write but cant read .

Any solution for this ?

This would be good, because on delphi currency calculations have a precision that float doesnt have, when we calc with float the rounds are done with a method that not every time is correct , but with currency is correct.

Why we use a database normaly is only to store data and applications do the calculation ( so float on postgres is error safe but calc are needed on client side not on server side, and is a bit mess to getting all float field and add a mask of 0.00 € manually ) so it shouldnt be deprecaded on zeos.

Thanks

Posted: 24.02.2012, 19:54
by EgonHugeist
the docs of PG says this type is deprecated. But i've fixed this in branch tsting and my private branch testing-egonhugeist. PG results the regional-currency as prefix like €+2.000,12 which breaks the rules of StrToFloatDef. Problem 1: the prefix. Problem 2 the wrong defined thausends and floating-point operaters.

So can you please test my branch and do some additional bug-reports?

Best regards EgonHugeist

Posted: 26.02.2012, 14:30
by sfxcc
Where can i get your branch test ?


Why Money a float and not delphi currency ? Being currency is better because several components have already prepared for currency.

Even so float calc have round errors with will cause a huge money deviation on a calc, with a few line it could cause more than 1 euro deviation.

I looking for the code and i dont found where it gets the value from pg and convert it to dataset value, can you send me the filename

Posted: 26.02.2012, 16:03
by EgonHugeist
sfxcc wrote:Where can i get your branch test ?


Why Money a float and not delphi currency ? Being currency is better because several components have already prepared for currency.
This is a Zeos-Internal function, which works generally with the Extendet-type. So don't worry everything is fine..

You can get thew sources either on http://zeoslib.svn.sourceforge.net/view ... es/testing or
http://zeoslib.svn.sourceforge.net/view ... gonhugeist

for the last one you have to know more about. Look at http://zeos.firmos.at/viewtopic.php?t=3427

Posted: 26.02.2012, 17:38
by sfxcc
I have done a simple change, try it out it worked because it results R$0,00
so it have R and , not correct it depends on location.

I change a value from a grid to 4,3 (Money on pg ) and it prints out 4,30000019073486

which is that round error i was talking about, can you check this and please change it to currency. it didnt even show the € not round to 2 places etc and the biggest prob is we use money to do calc with it .. is supposed to be the most accuracy or big probs coming out.

Money=ftFloat should be Money = ftCurrency delphi have this currency to avoid miscaculation with usual float error because math processor.
function SQLStrToFloatDef(Str: string; Def: Extended): Extended;
var
{$IFDEF DELPHI12_UP}
OldDecimalSeparator: WideChar;
OldThousandSeparator: WideChar;
{$ELSE}
OldDecimalSeparator: Char;
OldThousandSeparator: Char;
{$ENDIF}
aSymbolPos: Integer;
begin
OldDecimalSeparator := DecimalSeparator;
OldThousandSeparator := ThousandSeparator;
// DecimalSeparator := '.';
// ThousandSeparator := ',';
aSymbolPos := Pos('$', Str);
if aSymbolPos > 0 then
Str := Copy(Str, aSymbolPos+1, Pred(Length(Str)));
If Str = '' then
Result := Def
else
Result := StrToFloatDef(Str, Def);
DecimalSeparator := OldDecimalSeparator;
ThousandSeparator := OldThousandSeparator;
end;

Posted: 26.02.2012, 17:47
by EgonHugeist
Like i wrote you before the patch is done in the testing branches of sf.net. There i've also changed the ftFloat to ftDouble(Extendet-type) because i know about the rounding-problems. You can find the field-arrangements in ZDbcPostrgreUtils.pas...