Re: How To Get Numetic Value!!! using C ???

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: ovs(at)megalog(dot)ru
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How To Get Numetic Value!!! using C ???
Date: 2002-11-25 20:28:43
Message-ID: 3DE287FB.1070500@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Oleg Shalnev wrote:
> Hi All!
>
>
> I want to GetValue numeric type from binary cursor, but I have no ideas
> how to do it.
> Now I am using
>
> double test;
> test=atof((char*)GetValue(0,0));
> in C function and doing
> to_char(my_numeric_field, '9999999999999D99')
> in database selection.
> May be there is another normal way to do it.
>
> Thanks a lot!!!
> Oleg Shalnev

First, I'd not use binary cursors because:

1) I have no clue regarding the binary representation of Numeric
2) Byte-ordering can differ if the client and server platforms
are different

I'm surprised the above works at all with a binary cursor.
Assuming a text cursor, I think you need some additional C/C++
library which has:

1) support for ASCII to fixed-point conversion
2) support for fixed-point to ASCII conversion
3) fixed-point operations

My clients are CORBA-based C++, which has a "Fixed" class
supplied by the vendor to handle the above. Java, likewise, has
BigDecimal. You might want to do a search for "arbitrary
precision library C". A quick search included this:

http://www.swox.com/gmp/#DOC

which appears to do what you need to do on the client, and a
whole lot more...

How that helps,

Mike Mascari
mascarm(at)mascari(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2002-11-25 20:36:16 Re: caveats upgrading from 7.0.3 to 7.2.x
Previous Message Peter Childs 2002-11-25 20:15:34 What are my foreign Keys?