Skip to content

Commit

Permalink
Merge pull request #3305 from OSGeo/backport-3300-to-9.1
Browse files Browse the repository at this point in the history
[Backport 9.1] JSON output: avoid rounding issues with integer values in a double on…
  • Loading branch information
rouault authored Aug 27, 2022
2 parents 7d3c242 + 6e791c1 commit cc8970d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/proj_json_streaming_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

/*! @cond Doxygen_Suppress */

#include <limits>
#include <vector>
#include <string>

Expand Down Expand Up @@ -277,6 +278,14 @@ void CPLJSonStreamingWriter::Add(double dfVal, int nPrecision)
{
Print( dfVal > 0 ? "\"Infinity\"" : "\"-Infinity\"" );
}
else if( dfVal >= std::numeric_limits<int>::min() &&
dfVal <= std::numeric_limits<int>::max() &&
static_cast<int>(dfVal) == dfVal )
{
// Avoid rounding issues on some platforms like armel, with numbers
// like 2005. See https://github.com/OSGeo/PROJ/issues/3297
Print(CPLSPrintf("%d", static_cast<int>(dfVal)));
}
else
{
char szFormatting[10];
Expand Down

0 comments on commit cc8970d

Please sign in to comment.