std::string SEXPR::AsString() Do not allow scientific notation for doubles.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22902
This commit is contained in:
jean-pierre charras
2026-02-01 12:57:08 +01:00
parent 1f0e505063
commit 3b1cdb2d37
2 changed files with 20 additions and 3 deletions
+1
View File
@@ -38,6 +38,7 @@ target_include_directories( sexpr PUBLIC
# the s-exp parser has a dep on the wxFile methods
target_link_libraries( sexpr
fmt::fmt
${wxWidgets_LIBRARIES}
)
+19 -3
View File
@@ -23,6 +23,7 @@
#include <iomanip>
#include <sstream>
#include <wx/debug.h>
#include <fmt/core.h>
namespace SEXPR
{
@@ -195,9 +196,24 @@ namespace SEXPR
}
else if( IsDouble() )
{
std::stringstream out;
out << std::setprecision( 16 ) << GetDouble();
result += out.str();
std::string out;
out = fmt::format( "{:.10g}", GetDouble() );
// Scientific notation not allowed. So detect and change it
if( out.find("e") != std::string::npos )
{
out = fmt::format( "{:.10f}", GetDouble() );
// remove trailing zeros
while( !out.empty() && out[out.size() - 1] == '0' )
out.pop_back();
// we may have just stripped all the zeros after the decimal
if( out.size() > 1 && out[out.size() - 1] == '.' )
out.pop_back();
}
result += out;
}
return result;