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:
parent
45329ceafa
commit
617755f991
|
@ -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 )
|
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' )
|
while( --len > 0 && buf[len] == '0' )
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
|
|
||||||
if( buf[len]=='.' || buf[len]==',' )
|
if( len >= 0 && ( buf[len]=='.' || buf[len]==',' ) )
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
else
|
|
||||||
++len;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( aUnits == EDA_UNITS::MILS )
|
snprintf( buf, sizeof( buf ) - 1, "%.10g", value_to_print );
|
||||||
len = sprintf( buf, "%.7g", value_to_print );
|
|
||||||
else
|
|
||||||
len = sprintf( buf, "%.10g", value_to_print );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString stringValue( buf, wxConvUTF8 );
|
wxString stringValue( buf, wxConvUTF8 );
|
||||||
|
|
Loading…
Reference in New Issue