Re: "money" binary representation

From: Konstantin Izmailov <pgfizm(at)gmail(dot)com>
To: John R Pierce <pierce(at)hogranch(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: "money" binary representation
Date: 2009-11-16 05:10:44
Message-ID: 72746b5e0911152110m376fabd1ob174e63e91dd666f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Right, the value is '$51.20'! Now I understand how to interpret the bytes -
thank you!

I had to work with an existing database and I do not know why they still use
"money" fields.
On Sun, Nov 15, 2009 at 9:38 PM, John R Pierce <pierce(at)hogranch(dot)com> wrote:

> Konstantin Izmailov wrote:
>
>> 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.
>> Would you please help me find a method of converting binary "money" data
>> into a double precision?
>>
>>
>
> Its my understanding that MONEY is deprecated that you really should store
> money values as NUMERIC instead.
>
> a wild guess says thats some variant on NUMERIC, which is stored in base
> 10000 as a series of 16 bit integers, with a fuixed point fraction.
>
> why would you convert money to floating point? $0.10 in binary floating
> point is a repeating fraction which can't be represented exactly
>
> btw, are you sure your value isn't $51.20 ? 0x1400 is 5120 decimal.
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Konstantin Izmailov 2009-11-16 05:30:01 passing parameters to multiple statements
Previous Message Tom Lane 2009-11-16 05:10:37 Re: "money" binary representation