diff --git a/common/base_units.cpp b/common/base_units.cpp index 191896a31e..91ca6a3f6c 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -81,7 +81,7 @@ std::string Double2Str( double aValue ) { // For these values, %g works fine, and sometimes %f // gives a bad value (try aValue = 1.222222222222, with %.16f format!) - len = sprintf( buf, "%.16g", aValue ); + len = sprintf( buf, "%.10g", aValue ); } return std::string( buf, len ); @@ -437,6 +437,7 @@ void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits ) long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA_DATA_TYPE aType ) { double value = DoubleValueFromString( aUnits, aTextValue, aType ); + return KiROUND( value ); } diff --git a/common/libeval/numeric_evaluator.cpp b/common/libeval/numeric_evaluator.cpp index 73f90677a7..6e44399651 100644 --- a/common/libeval/numeric_evaluator.cpp +++ b/common/libeval/numeric_evaluator.cpp @@ -107,7 +107,10 @@ void NUMERIC_EVALUATOR::parseSetResult( double val ) else { // Can be printed as a floating point - snprintf( m_token.token, m_token.OutLen, "%.10g", val ); + // Warning: DO NOT use a format like %f or %g, because they can create issues. + // especially %g can generate an exponent, incompatible with UNIT_BINDER + // Use the optimized Double2Str + snprintf( m_token.token, m_token.OutLen, "%s", Double2Str( val ).c_str() ); } }