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.
Artikkel-ID: 11558 – Forrige gjennomgang: 9. des. 2005 – Revisjon: 1