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 <float.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <locale.h>
|
||||||
#include "cjson.h"
|
#include "cjson.h"
|
||||||
|
|
||||||
static const char *ep;
|
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. */
|
/* Render the number nicely from the given item into a string. */
|
||||||
static char *print_number(cJSON *item)
|
static char *print_number(cJSON *item)
|
||||||
{
|
{
|
||||||
|
char * locale = setlocale(LC_ALL, NULL);
|
||||||
|
setlocale(LC_NUMERIC, "C");
|
||||||
|
|
||||||
char *str;
|
char *str;
|
||||||
double d=item->valuedouble;
|
double d=item->valuedouble;
|
||||||
if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
|
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);
|
else sprintf(str,"%f",d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setlocale(LC_NUMERIC, locale);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "config_helper.h"
|
#include "config_helper.h"
|
||||||
|
|
||||||
|
#include <clocale>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -37,7 +38,13 @@ namespace alpr
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char * locale = std::setlocale(LC_ALL, NULL);
|
||||||
|
setlocale(LC_NUMERIC, "C");
|
||||||
|
|
||||||
float val = atof(pszValue);
|
float val = atof(pszValue);
|
||||||
|
|
||||||
|
std::setlocale(LC_NUMERIC, locale);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,13 +58,18 @@ namespace alpr
|
|||||||
values.sort(CSimpleIniA::Entry::LoadOrder());
|
values.sort(CSimpleIniA::Entry::LoadOrder());
|
||||||
|
|
||||||
std::vector<float> response;
|
std::vector<float> response;
|
||||||
|
|
||||||
// output all of the items
|
char * locale = std::setlocale(LC_ALL, NULL);
|
||||||
|
std::setlocale(LC_NUMERIC, "C");
|
||||||
|
|
||||||
|
// output all of the items
|
||||||
CSimpleIniA::TNamesDepend::const_iterator i;
|
CSimpleIniA::TNamesDepend::const_iterator i;
|
||||||
for (i = values.begin(); i != values.end(); ++i) {
|
for (i = values.begin(); i != values.end(); ++i) {
|
||||||
response.push_back(atof(i->pItem));
|
response.push_back(atof(i->pItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::setlocale(LC_NUMERIC, locale);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user