diff --git a/libs/sexpr/CMakeLists.txt b/libs/sexpr/CMakeLists.txt index 2614a4fc80..6a7b0a7c0a 100644 --- a/libs/sexpr/CMakeLists.txt +++ b/libs/sexpr/CMakeLists.txt @@ -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} ) diff --git a/libs/sexpr/sexpr.cpp b/libs/sexpr/sexpr.cpp index 44b20bd7a2..3594c799cc 100644 --- a/libs/sexpr/sexpr.cpp +++ b/libs/sexpr/sexpr.cpp @@ -23,6 +23,7 @@ #include #include #include +#include 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;