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.
This commit is contained in:
parent
86b1edf73e
commit
722d0d67e3
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue