... please wait while loading ...

To view the complete site without permanently having to scroll, your browser-window should be maximized to support your screen-resolution of .
CitiMap
Gerald Kreißl

facebook google

  17.377.053 Nedstat Basic - Kostenlose web site statistiken Persönliche Homepage webseite Zähler
Kostenlose Zähler
In memoriam C-BIT Information-Center Hannover (2.241/1075+2.241/1076 - no longer active)
Sicherheitshinweis: Wir weisen vorsorglich darauf hin, dass wir bei der Anmeldung saemtliche automatisch uebermittelten Parameter wie IP-Adresse und/oder Einwahlrufnummer speichern, um uns und unsere Kunden vor Missbrauch zu schuetzen. Selbstverstaendlich werden wir bei Bedarf umgehend strafrechtliche Massnahmen ergreifen, um einen vorliegenden Missbrauch zu ahnden.

How to convert a string to a floating-point number in C++

Article ID:11558
Last Review:December 9, 2005
Revision:4.0
This article was previously published under Q11558

SUMMARY

In an application developed with Microsoft C or C/C++, the sscanf() function is a good alternative to the atof() function to convert a string of digits into a floating-point number. If a string does not represent a valid number, atof() returns the value zero; sscanf() returns more useful error information. The application can use the error value from sscanf() with the matherr() function to perform error handling. The atof() function does not call matherr() unless an actual math exception occurs.

The text below presents two recommended methods to convert a string to a floating-point number.
 Validate the string to convert prior to calling the atof() function. Make sure that the string does not contain any non- numeric characters and that the decimal point and sign characters are in the correct locations.
 Use the sscanf() function. It is slower than the atof() function, but it provides better information when an error occurs.

APPLIES TO
 Microsoft C Professional Development System 6.0a
 Microsoft C Professional Development System 6.0a
 Microsoft Visual C++ 1.0 Professional Edition
 Microsoft Visual C++ 1.5 Professional Edition
 Microsoft Visual C++ 1.51
 Microsoft Visual C++ 1.52 Professional Edition
 Microsoft Visual C++ 2.0 Professional Edition
 Microsoft Visual C++ 2.1
 Microsoft Visual C++ 4.0 Standard Edition
 Microsoft Visual C++ 5.0 Enterprise Edition
 Microsoft Visual C++ 6.0 Enterprise Edition
 Microsoft Visual C++ 5.0 Professional Edition
 Microsoft Visual C++ 6.0 Professional Edition
 Microsoft Visual C++ 6.0 Standard Edition
 Microsoft Visual C++ .NET 2002 Standard Edition
 Microsoft Visual C++ .NET 2003 Standard Edition
 Microsoft Visual C++ 2005 Express Edition

Back to the top



This mirror is sponsored by:
Hansjoerg G. Henker
A-Z Consulting & Development
[3.155]

Information-Center [11.02.2012 22:47:02]