src/misc.cpp

changeset 308
4e2425bd4dc7
parent 286
7a562bf3d829
child 332
3013acb1df53
--- a/src/misc.cpp	Thu Jun 27 14:55:32 2013 +0300
+++ b/src/misc.cpp	Mon Jul 01 17:27:37 2013 +0300
@@ -249,6 +249,23 @@
 	return list.join (delim);
 }
 
+double atof( str val )
+{
+	// Disable the locale while parsing the line or atof's behavior changes
+	// between locales (i.e. fails to read decimals properly). That is
+	// quite undesired...
+	setlocale( LC_NUMERIC, "C" );
+	char* buf = new char[val.length()];
+	char* bufptr = &buf[0];
+	
+	for( qchar& c : val )
+		*bufptr++ = c.toAscii();
+	*bufptr = '\0';
+	
+	double fval = atof( buf );
+	delete[] buf;
+	return fval;
+}
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

mercurial