diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index c00ed843eb..154beb3af9 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -423,12 +423,16 @@ private: // Common part of all ctors. void Init() { - m_digits = 0; + DoSetDigits(0); } // Update m_digits and m_format to correspond to the given increment. void DetermineDigits(double inc); + // Set the number of digits and the format unconditionally. + void DoSetDigits(unsigned digits); + + wxString m_format; wxDECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble); diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index 8048e72682..1342acc478 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -753,9 +753,7 @@ void wxSpinCtrlDouble::SetDigits(unsigned digits) if ( digits == m_digits ) return; - m_digits = digits; - - m_format.Printf(wxT("%%0.%ulf"), digits); + DoSetDigits(digits); ResetTextValidator(); m_textCtrl->InvalidateBestSize(); @@ -763,6 +761,13 @@ void wxSpinCtrlDouble::SetDigits(unsigned digits) DoSetValue(m_value, SendEvent_None); } +void wxSpinCtrlDouble::DoSetDigits(unsigned digits) +{ + m_digits = digits; + + m_format.Printf(wxT("%%0.%ulf"), digits); +} + void wxSpinCtrlDouble::ResetTextValidator() { #if wxUSE_VALIDATORS @@ -774,17 +779,19 @@ void wxSpinCtrlDouble::ResetTextValidator() void wxSpinCtrlDouble::DetermineDigits(double inc) { + unsigned digits; + inc = fabs(inc); if ( inc > 0.0 && inc < 1.0 ) { - m_digits = wxMin(SPINCTRLDBL_MAX_DIGITS, -static_cast(floor(log10(inc)))); + digits = wxMin(SPINCTRLDBL_MAX_DIGITS, -static_cast(floor(log10(inc)))); } else { - m_digits = 0; + digits = 0; } - m_format.Printf("%%0.%ulf", m_digits); + DoSetDigits(digits); } #endif // wxUSE_SPINBTN