Search code examples
c++doubleatof

Converting a string like "2.12e-6" to a double


Is there a built in function in c++ that can handle converting a string like "2.12e-6" to a double?


Solution

  • atof should do the job. This how its input should look like:

    A valid floating point number for atof is formed by a succession of:
    
    An optional plus or minus sign 
    A sequence of digits, optionally containing a decimal-point character 
    An optional exponent part, which itself consists on an 'e' or 'E' character followed by an optional sign and a sequence of digits.