Re: [Vala] double to string without localization



Frederik wrote:
Hi,

I want to format a double to a string using an enforced dot (no comma) as decimal separator despite enabled localization after calling Gtk.init().

Both double.to_string() and string.printf() have localized results.

I'm missing the functions g_ascii_dtostr() and g_ascii_formatd().

http://library.gnome.org/devel/glib/stable/glib-String-Utility-Functions.html#g-ascii-dtostr
http://library.gnome.org/devel/glib/stable/glib-String-Utility-Functions.html#g-ascii-formatd

The documentation says:
"Converts a gdouble to a string, using the '.' as decimal point."

Or is there any other way to achieve this?

I have tried to bind it manually:

--------

using GLib;

[CCode (cname="g_ascii_dtostr", cheader_filename="glib.h")]
private extern string dtostr (double x);

public class DoubleToString {

        static int main (string[] args) {
//              Gtk.init (ref args);
                print ("%s\n", dtostr (3.1415));
                return 0;
        }
}

--------

But this results in an error:


doubletostring.c:12: error: conflicting types for 'g_ascii_dtostr'
/usr/include/glib-2.0/glib/gstrfuncs.h:142: error: previous declaration of 'g_ascii_dtostr' was here
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)

Any ideas?
Thanks

Frederik



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