Re: How to change float to char
- From: John Cupitt <john cupitt ng-london org uk>
- To: Skip Montanaro <skip pobox com>
- Cc: engenharia3 maqplas com br, gtk-list gnome org
- Subject: Re: How to change float to char
- Date: Mon, 16 Jul 2001 13:18:34 +0100
Skip Montanaro wrote:
> 
>     Flavio> I need to print float numbers in a gtk label and this widget
>     Flavio> only accept gchar in your text parameter, I want to know if
>     Flavio> exists some type of routine that changes float number in format
>     Flavio> a.bcde to char format "a.bcde".
> 
> Check out g_snprintf in the glib reference manual (section: String Utility
> Functions).  I believe you call it pretty much like you would sprintf, with
> the added safety feature that you provide the length of the output buffer so
> it doesn't scribble past the end of it:
> 
>     g_snprintf(buf, len_buf-1, "%6.4f", myfloat);
I find this useful:
--
void
set_labelf( GtkWidget *label, const char *fmt, ... )
{
        va_list ap;
        char *buf;
        va_start( ap, fmt );
        buf = g_strdup_vprintf( fmt, ap );
        va_end( ap );
        gtk_label_set_text( GTK_LABEL( label ), buf );
	g_free( buf );
}
--
John
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]