Re: [HACKERS] Datatype MONEY - Mailing list pgsql-hackers

From wieck@debis.com (Jan Wieck)
Subject Re: [HACKERS] Datatype MONEY
Date
Msg-id m11xWpt-0003kGC@orion.SAPserv.Hamburg.dsh.de
Whole thread Raw
In response to Re: [HACKERS] Datatype MONEY  (Karel Zak - Zakkr <zakkr@zf.jcu.cz>)
Responses Re: [HACKERS] Datatype MONEY
List pgsql-hackers
>  Well, on a datetype is depend only small part in to_char(), I try
> write to_char(numeric, text) version. But I must first explore
> NUMERIC datetupe... (documentation is quiet for this).

    NUMERIC's  output  function  returns a null terminated string
    representation as usual. Possibly a dash (negative sign), one
    or  more  digits,  optionally followed by a decimal point and
    one or more digits. And you could get  it  with  an  adjusted
    number of digits after the decimal point by doing

        text *numeric_to_char(Numeric num, format text)
        {
            char    *numstr;
            int32    scale;

            ... /* calculate the wanted number of digits */
            ... /* after DP in scale depending on format */

            numstr = numeric_out(numeric_round(num, scale));
        }

    There will be "scale" number of digits after the DP, which is
    missing if scale is zero. The value will  be  correct  rouded
    and/or zero padded at the end.

    Wouldn't that be enough for you?

    Well,  you  must  work  on the string only and cannot read it
    into a float internally, but with the above preprocessing, it
    should be fairly simple.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#========================================= wieck@debis.com (Jan Wieck) #

pgsql-hackers by date:

Previous
From: Michael Meskes
Date:
Subject: Re: [HACKERS] Datatype MONEY
Next
From: wieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] Datatype MONEY