Split up Double2Str to a format function to make its use case clear

This commit is contained in:
Marek Roszko
2022-09-17 00:10:22 -04:00
parent 59a9ddac20
commit ece23d434b
15 changed files with 140 additions and 107 deletions
+25 -1
View File
@@ -28,6 +28,7 @@
#include <clocale>
#include <cmath>
#include <fmt/core.h>
#include <macros.h>
#include <richio.h> // StrPrintf
#include <string_utils.h>
@@ -1088,7 +1089,30 @@ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
}
std::string Double2Str( double aValue )
std::string FormatDouble2Str( double aValue )
{
std::string buf;
if( aValue != 0.0 && std::fabs( aValue ) <= 0.0001 )
{
buf = fmt::format( "{:.16f}", aValue );
// remove trailing zeros
while( !buf.empty() && buf[buf.size() - 1] == '0' )
{
buf.pop_back();
}
}
else
{
buf = fmt::format( "{:.10g}", aValue );
}
return buf;
}
std::string UIDouble2Str( double aValue )
{
char buf[50];
int len;