Treat all units equally when converting to string

Excessive trucation in mils can lead to data loss when round-tripping
values.  Better to keep decimal count consistent between units

Fixes https://gitlab.com/kicad/code/kicad/issues/11878

(cherry picked from commit 67d9729311)
This commit is contained in:
Seth Hillbrand 2022-06-21 15:18:58 -07:00
parent 45329ceafa
commit 617755f991
1 changed files with 3 additions and 8 deletions

View File

@ -226,22 +226,17 @@ wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol,
if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
{
len = sprintf( buf, "%.10f", value_to_print );
len = snprintf( buf, sizeof( buf ) - 1, "%.10f", value_to_print );
while( --len > 0 && buf[len] == '0' )
buf[len] = '\0';
if( buf[len]=='.' || buf[len]==',' )
if( len >= 0 && ( buf[len]=='.' || buf[len]==',' ) )
buf[len] = '\0';
else
++len;
}
else
{
if( aUnits == EDA_UNITS::MILS )
len = sprintf( buf, "%.7g", value_to_print );
else
len = sprintf( buf, "%.10g", value_to_print );
snprintf( buf, sizeof( buf ) - 1, "%.10g", value_to_print );
}
wxString stringValue( buf, wxConvUTF8 );