mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 15:57:01 +08:00
Merge pull request #401 from abankowski/master
Set locale to avoid numeric conversion issues
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include "cjson.h"
|
||||
|
||||
static const char *ep;
|
||||
@@ -117,6 +118,9 @@ static const char *parse_number(cJSON *item,const char *num)
|
||||
/* Render the number nicely from the given item into a string. */
|
||||
static char *print_number(cJSON *item)
|
||||
{
|
||||
char * locale = setlocale(LC_ALL, NULL);
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
char *str;
|
||||
double d=item->valuedouble;
|
||||
if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
|
||||
@@ -134,6 +138,8 @@ static char *print_number(cJSON *item)
|
||||
else sprintf(str,"%f",d);
|
||||
}
|
||||
}
|
||||
|
||||
setlocale(LC_NUMERIC, locale);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "config_helper.h"
|
||||
|
||||
#include <clocale>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
@@ -37,7 +38,13 @@ namespace alpr
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
char * locale = std::setlocale(LC_ALL, NULL);
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
float val = atof(pszValue);
|
||||
|
||||
std::setlocale(LC_NUMERIC, locale);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -52,12 +59,17 @@ namespace alpr
|
||||
|
||||
std::vector<float> response;
|
||||
|
||||
char * locale = std::setlocale(LC_ALL, NULL);
|
||||
std::setlocale(LC_NUMERIC, "C");
|
||||
|
||||
// output all of the items
|
||||
CSimpleIniA::TNamesDepend::const_iterator i;
|
||||
for (i = values.begin(); i != values.end(); ++i) {
|
||||
response.push_back(atof(i->pItem));
|
||||
}
|
||||
|
||||
std::setlocale(LC_NUMERIC, locale);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user