Fallback to scientific notation when fixed-point is long

Fixed point output can create arbitrarily long string representations of
floating points.  When this happens, we would like to just represent the
scientific notation to a limited precision

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17890

(cherry picked from commit 24f02e72d0)
This commit is contained in:
Seth Hillbrand 2024-05-06 12:59:05 -07:00
parent 6a55a47276
commit b39b54a92e
1 changed files with 5 additions and 0 deletions

View File

@ -262,6 +262,11 @@ wxString SPICE_VALUE::ToString( const SPICE_VALUE_FORMAT& aFormat )
mantissa *= std::pow( 10, scale - aFormat.Precision + 1 ); mantissa *= std::pow( 10, scale - aFormat.Precision + 1 );
wxString res = wxString::FromCDouble( mantissa, std::max( 0, aFormat.Precision - scale - 1 ) ); wxString res = wxString::FromCDouble( mantissa, std::max( 0, aFormat.Precision - scale - 1 ) );
// If we have an excessively long number, switch to scientific notation
if( ssize_t( res.length() ) > aFormat.Precision + scale + 1 )
res = wxString::FromCDouble( mantissa );
return res + range; return res + range;
} }