Re: geting the value of an entry like a float




   ato* friends fails conversion if the "number" has illegal characters.
   Perhaps you should copy the value to a temp char*  variable and trim all the
white spaces/new lines. Note also that ato* does not check for errors on the
conversion.

   You probably should use strtoll and firends since they provide error
checking.. Better yet, use the glib wrappers around them, for platform
independence. The docs are at:
  
http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.html#g-ascii-strtoull

  NOTE: with the above functions, you still have to remove the illegal chars.

  You can trim the white spaces using g_strstrip()

http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.html#g-strstrip

   Boa Sorte.

Harring Figueiredo.


   

--- Murilo Tuvani <murilo_tuvani yahoo com br> wrote:
I'm trying to get the value of an entry and convert it
with atof(), but it allways return 0. The spinbutton
is ok!. Is there a way so I do not net to use
g_locate_to... I just want to use locale char, what do
I do?

float valor_unitario, quantidade, total;
  gpointer ponteiro;
 

ponteiro=gtk_object_get_data(GTK_OBJECT(window_itens),"entry_valor_unitario");
  g_print("\nValor unitario %s, (STR)
%10.2f",gtk_entry_get_text(GTK_ENTRY(ponteiro)),
  (float)
atof(gtk_entry_get_text(GTK_ENTRY(ponteiro))));
  g_print("\nValor unitario %s, (TO)
%10.2f",g_locale_to_utf8(gtk_entry_get_text(GTK_ENTRY(ponteiro)),
-1, NULL, NULL, NULL),
  (float)
atof(g_locale_to_utf8(gtk_entry_get_text(GTK_ENTRY(ponteiro)),
-1, NULL, NULL, NULL)));
  g_print("\nValor unitario %s, (FROM)
%10.2f",g_locale_from_utf8(gtk_entry_get_text(GTK_ENTRY(ponteiro)),
-1, NULL, NULL, NULL),
  (float)
atof(g_locale_from_utf8(gtk_entry_get_text(GTK_ENTRY(ponteiro)),
-1, NULL, NULL, NULL)));
 

valor_unitario=(float)atof(g_locale_from_utf8(gtk_entry_get_text(GTK_ENTRY(ponteiro)),
-1, NULL, NULL, NULL));
 
ponteiro=gtk_object_get_data(GTK_OBJECT(window_itens),"spinbutton_qtd");
 
quantidade=(float)gtk_spin_button_get_value(GTK_SPIN_BUTTON(ponteiro));
  total=valor_unitario*quantidade;
 
g_print("\nUnit\t%10.2f\nQTD\t%10.2f\nTotal\t%10.2f",
valor_unitario, quantidade, total);



      
      
              
_______________________________________________________
Yahoo! Mail agora com 100MB, anti-spam e antivírus grátis!
http://br.info.mail.yahoo.com/
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




                
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 



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