From 722d0d67e32cf543d3c84dc31d2443c0e7454317 Mon Sep 17 00:00:00 2001 From: "v.audacity" Date: Sat, 28 Aug 2010 23:41:30 +0000 Subject: [PATCH] In the case where Internat::ToDisplayString gets no specified precision, do not strip all trailing zeros. Leave the decimal separator and one zero. This makes edit-texts associated with sliders consistently show at least one decimal point of precision as the slider moves. It also fixes a bug in Nyquist dynamic typing of the result from a real/float slider, where if the value string had no decimal point it got typed as a FIXNUM instead of FLONUM. --- src/Internat.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Internat.cpp b/src/Internat.cpp index 9e1455c98..911e106f1 100644 --- a/src/Internat.cpp +++ b/src/Internat.cpp @@ -89,7 +89,7 @@ wxString Internat::ToString(double numberToConvert, } wxString Internat::ToDisplayString(double numberToConvert, - int digitsAfterDecimalPoint /* = -1 */) + int digitsAfterDecimalPoint /* = -1 */) { wxString decSep = wxString(GetDecimalSeparator()); wxString result; @@ -99,20 +99,24 @@ wxString Internat::ToDisplayString(double numberToConvert, result.Printf(wxT("%f"), numberToConvert); // Not all libcs respect the decimal separator, so always convert - // any dots found to the decimal separator + // any dots found to the decimal separator. result.Replace(wxT("."), decSep); if (result.Find(decSep) != -1) { - // Strip trailing zeros + // Strip trailing zeros, but leave one, and decimal separator. int pos = result.Length() - 1; - while (pos > 0 && result.GetChar(pos) == wxT('0')) + while ((pos > 1) && + (result.GetChar(pos) == wxT('0')) && + (result.GetChar(pos - 1) != decSep)) pos--; - if (result.GetChar(pos) == decSep) - pos--; // strip point before empty fractional part + // (Previous code removed all of them and decimal separator.) + // if (result.GetChar(pos) == decSep) + // pos--; // strip point before empty fractional part result = result.Left(pos+1); } - } else + } + else { wxString format; format.Printf(wxT("%%.%if"), digitsAfterDecimalPoint);