Revert "Use {fmt} for double -> string conversions"
This reverts commit 03fff6e58d
This commit is contained in:
parent
281b9d405a
commit
75ae0d8e5e
|
@ -35,7 +35,6 @@
|
|||
*/
|
||||
|
||||
#include <base_units.h>
|
||||
#include <fmt/format.h>
|
||||
#include <string_utils.h>
|
||||
#include <math/util.h> // for KiROUND
|
||||
#include <macros.h>
|
||||
|
@ -214,24 +213,24 @@ wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol,
|
|||
value_to_print = To_User_Unit( aUnits, value_to_print );
|
||||
}
|
||||
|
||||
std::string buf;
|
||||
char buf[50];
|
||||
|
||||
if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
|
||||
{
|
||||
buf = fmt::format( "{:.16f}", value_to_print );
|
||||
int len = snprintf( buf, sizeof( buf ) - 1, "%.10f", value_to_print );
|
||||
|
||||
// remove trailing zeros
|
||||
while( !buf.empty() && buf[buf.size() - 1] == '0' )
|
||||
{
|
||||
buf.pop_back();
|
||||
}
|
||||
while( --len > 0 && buf[len] == '0' )
|
||||
buf[len] = '\0';
|
||||
|
||||
if( len >= 0 && ( buf[len]=='.' || buf[len]==',' ) )
|
||||
buf[len] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = fmt::format( "{:.10g}", value_to_print );
|
||||
snprintf( buf, sizeof( buf ) - 1, "%.10g", value_to_print );
|
||||
}
|
||||
|
||||
wxString stringValue( buf );
|
||||
wxString stringValue( buf, wxConvUTF8 );
|
||||
|
||||
if( aAddUnitSymbol )
|
||||
stringValue += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType );
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include <macros.h>
|
||||
#include <richio.h> // StrPrintf
|
||||
#include <string_utils.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1091,27 +1090,29 @@ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
|
|||
|
||||
std::string Double2Str( double aValue )
|
||||
{
|
||||
std::string buf;
|
||||
char buf[50];
|
||||
int len;
|
||||
|
||||
if( aValue != 0.0 && std::fabs( aValue ) <= 0.0001 )
|
||||
{
|
||||
// For these small values, 'f' works fine,
|
||||
// and 'g' can result in exponent notation
|
||||
buf = fmt::format( "{:.16f}", aValue );
|
||||
// For these small values, %f works fine,
|
||||
// and %g gives an exponent
|
||||
len = sprintf( buf, "%.16f", aValue );
|
||||
|
||||
// remove trailing zeros
|
||||
while( !buf.empty() && buf[buf.size() - 1] == '0' )
|
||||
{
|
||||
buf.pop_back();
|
||||
}
|
||||
while( --len > 0 && buf[len] == '0' )
|
||||
buf[len] = '\0';
|
||||
|
||||
if( buf[len] == '.' )
|
||||
buf[len] = '\0';
|
||||
else
|
||||
++len;
|
||||
}
|
||||
else
|
||||
{
|
||||
// For these values, 'g' works fine, and sometimes 'f'
|
||||
// For these values, %g works fine, and sometimes %f
|
||||
// gives a bad value (try aValue = 1.222222222222, with %.16f format!)
|
||||
buf = fmt::format( "{:.10g}", aValue );
|
||||
len = sprintf( buf, "%.10g", aValue );
|
||||
}
|
||||
|
||||
return buf;
|
||||
return std::string( buf, len );
|
||||
}
|
Loading…
Reference in New Issue