# HG changeset patch # User Santeri Piippo # Date 1363709559 -7200 # Node ID 2b0569fee5ad310639162c19ed473a3923dcbebd # Parent d99006de6261e207a138e2c1d7eabdd2a400be4f Temporarily set the locale to C when using ftoa, or the resulting string is subject to the locale and gets unexpected symbols (e.g. commas for the decimal dots while the function expects periods) diff -r d99006de6261 -r 2b0569fee5ad misc.cpp --- a/misc.cpp Tue Mar 19 17:21:51 2013 +0200 +++ b/misc.cpp Tue Mar 19 18:12:39 2013 +0200 @@ -16,8 +16,9 @@ * along with this program. If not, see . */ +#include +#include #include "common.h" -#include double getWordFloat (str& s, const ushort n) { return atof ((s / " ")[n]); @@ -67,6 +68,10 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= str ftoa (double fCoord) { + // Disable the locale first so that the decimal point will not + // turn into anything weird (like commas) + setlocale (LC_NUMERIC, "C"); + str zRep = str::mkfmt ("%.3f", fCoord); // Remove trailing zeroes @@ -78,6 +83,8 @@ if (zRep[~zRep - 1] == '.') zRep -= 1; + // Reset the locale + setlocale (LC_NUMERIC, ""); return zRep; }