Re: convert char * to double



I hope this little bit of code can help you, I have not test it in a case like yours but I have never received a complain, yet!
const float jme::strtools::toFloat( const std::string& s )
throw ( jme::strtoolsEx ) {
   if ( s.empty() )
       throw jme::strtoolsEx( str_empty, FILE, METHOD, LINE );
   std::istringstream iss( s );
   float num;
   //If the data extracted from 'iss' is successfully assingned to
   // ival and iss retuns false
   if ( iss >> num && iss.eof() )
       return num;
   else
       throw jme::strtoolsEx( fe_eof_bit, FILE, METHOD, LINE );

   /*
   if(s.empty()) throw jme::strtoolsEx(STR_EMPTY,FILE,METHOD,LINE);
   return atof( s.c_str() );
   */
}

* You cannot exercise your power to a point of humiliation.
                      - Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

* If that document has fine printing anywhere, just chuck it in the garbage
                     - Jorge Escalante
Ma'assalama! Adiós! bye!

-----Original Message-----
From: Jonathon Jongsma <jonathon jongsma gmail com>
To: Mickael Drean <mickael drean gmail com>
Cc: gtkmm-list gnome org
Sent: Fri, 24 Feb 2006 10:56:15 -0600
Subject: Re: convert char * to double

On 2/24/06, Mickael Drean <mickael drean gmail com> wrote:
Hello,

  I'm not sure but maybe  " istringstream " method can help you.

Bye

Yeah, you could try something like this:
  std::istringstream istrm(number_string);
  double number;
  istrm >> number;

I believe istringstream should honor your locale and parse the comma
as a decimal separator (though I haven't tested it).  But if not, you
may need to mess around with istringstream::imbue() or something
similar.

Jonner
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list

___________________________________________________
Try the New Netscape Mail Today!
Virtually Spam-Free | More Storage | Import Your Contact List
http://mail.netscape.com



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