From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Jasen Betts <jasen(at)xnet(dot)co(dot)nz> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: "money" binary representation |
Date: | 2009-11-17 01:56:51 |
Message-ID: | b42b73150911161756x3dd1817aw85f746241d132350@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Nov 16, 2009 at 3:02 AM, Jasen Betts <jasen(at)xnet(dot)co(dot)nz> wrote:
> On 2009-11-16, Konstantin Izmailov <pgfizm(at)gmail(dot)com> wrote:
>> --000e0cd5d09230ff7d04787526aa
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> I'm trying to read "money" field using PQgetvalue (PostgreSQL 8.3.7). The
>> function returns 9 bytes, smth like 0h 0h 0h 0h 0h 0h 14h 0h 0h, for the
>> value '$50.2'. I could not find description anywhere on how to convert the
>> binary data into, for example, a double precision number.
>
> money is a 64 bit integer representing a number of cents, it appears
> to be big-endian byte order on ypur system
>
> it is deprecated and should not be used in new applications, use some
> sort of numeric instead.
>
>> Would you please help me find a method of converting binary "money" data
>> into a double precision?
>
> floating point is not recomended for financial calculations, but
> dividing the integer value by 100.0 should get you there.
if you are reading/writing binary data to/from postgres, you should
consider using libpqtypes:
PGmoney m;
res = PQexecf(conn, "INSERT INTO foo(m) values(%money) returning m", m);
PQgetf(res, 0, "#money", "m", &m); /* # notation pulls field by name */
boy, this question sure seems to come up an awful lot!
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Chernow | 2009-11-17 02:03:21 | Re: "money" binary representation |
Previous Message | Raymond O'Donnell | 2009-11-16 23:12:01 | Re: specifying a password on the cmd line for db connect |