Skip to content

Commit 19cda6a

Browse files
rouaultgithub-actions[bot]
authored andcommitted
JSON export: avoid non-significant decimal digits in version field (fixes OSGeo#3863)
1 parent 4f0376b commit 19cda6a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/iso19111/metadata.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,11 @@ void Identifier::_exportToWKT(WKTFormatter *formatter) const {
10881088
formatter->addQuotedString(l_code);
10891089
}
10901090
if (!l_version.empty()) {
1091-
try {
1092-
(void)c_locale_stod(l_version);
1091+
bool isDouble = false;
1092+
(void)c_locale_stod(l_version, isDouble);
1093+
if (isDouble) {
10931094
formatter->add(l_version);
1094-
} catch (const std::exception &) {
1095+
} else {
10951096
formatter->addQuotedString(l_version);
10961097
}
10971098
}
@@ -1140,16 +1141,17 @@ void Identifier::_exportToJSON(JSONFormatter *formatter) const {
11401141

11411142
if (!l_version.empty()) {
11421143
writer->AddObjKey("version");
1143-
try {
1144-
const double dblVersion = c_locale_stod(l_version);
1144+
bool isDouble = false;
1145+
const double dblVersion = c_locale_stod(l_version, isDouble);
1146+
if (isDouble) {
11451147
if (dblVersion >= std::numeric_limits<int>::min() &&
11461148
dblVersion <= std::numeric_limits<int>::max() &&
11471149
static_cast<int>(dblVersion) == dblVersion) {
11481150
writer->Add(static_cast<int>(dblVersion));
11491151
} else {
1150-
writer->Add(dblVersion);
1152+
writer->Add(dblVersion, /*precision=*/15);
11511153
}
1152-
} catch (const std::exception &) {
1154+
} else {
11531155
writer->Add(l_version);
11541156
}
11551157
}

0 commit comments

Comments
 (0)