Re: [gnome-db] Gda_Value_Stringify of a double

On 10/23/06, Murray Cumming <murrayc murrayc com> wrote:
On Mon, 2006-10-23 at 09:51 -0300, Juan Pablo wrote:
> Hello list.
> When i use this function with a gda value double, it generates a 2
> decimal number, rounding it up. For example, 0.895 double becomes "0.90"
> string.
> I would like to have 4 decimas. Is this a parameter?

No, it's not. If you need more decimals, write your own function, or
use Murray's one as proposed if we integrate it into Libgda (see the
end of this mail).

I can't see what possible use this function has:

 * gda_value_stringify
 * @value: a #GValue.
 * Converts a GValue to its string representation which is a human
readable value. Note that the
 * returned string does not take into account the current locale of the
user (on the contrary to the
 * #GdaDataHandler objects).
 * Dates are converted in a YYYY-MM-DD format.
 * Returns: a new string, or %NULL if the conversion cannot be done.
Free the value with a g_free() when you've finished
 * using it.

It says that string is meant to be human-readable, but it ignores the
current locale, and it makes assumptions about the numeric formatting
wanted. So it's no use for actually showing to a human. I suggest that
it be marked as "useful only for debugging, and not for showing values
in your user interface."

It is also very usefull when you want to save a value in an (XML for
example) file and you need to be able to read it back even if the
locale has changed.

If you want to take into account the locale, then you should use the
GdaDataHandler which both takes into account the locale and any syntax
specific to a DBMS. GdaDataHandler objects are created and managed by
each provider and you can use them just after having obtained a
pointer to one using gda_server_provider_get_data_handler_gtype() or

> Meanwhile, i made a function wich does the same BUT it uses a static
> buffer for the return and the format is parametrizable. No need to use
> intermediate variables which needs to be freed.
> Is there any reason to not to do so with gda_value_stringify? (the
> static char part) If the string is needed on a new var you just strdup
> it.

A lot of code now assumes the current behaviour, and it would be very
risky to change that now (being so close to a 2.0). However we could
add a gda_value_stingify_static() function which does what you



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]