Determine number of digits correctly when increment > 1
Using increment greater than 1 but with a fractional part should still work, i.e. should use enough digits to fully show the fractional part of the numbers that can be obtained by using this increment.
This commit is contained in:
parent
0153a6673e
commit
6c9c0ba02b
@ -805,8 +805,10 @@ void wxSpinCtrlDouble::ResetTextValidator()
|
||||
/* static */
|
||||
unsigned wxSpinCtrlDouble::DetermineDigits(double inc)
|
||||
{
|
||||
// TODO-C++11: Use std::modf() to get the fractional part.
|
||||
inc = fabs(inc);
|
||||
if ( inc > 0.0 && inc < 1.0 )
|
||||
inc -= static_cast<int>(inc);
|
||||
if ( inc > 0.0 )
|
||||
{
|
||||
return wxMin(SPINCTRLDBL_MAX_DIGITS, -static_cast<int>(floor(log10(inc))));
|
||||
}
|
||||
|
@ -236,6 +236,12 @@ TEST_CASE_METHOD(SpinCtrlDoubleTestCase,
|
||||
m_spin->SetIncrement(0.001);
|
||||
m_spin->SetValue(1.23456789);
|
||||
CHECK( m_spin->GetTextValue() == "1.23457" );
|
||||
|
||||
// Check that using increment greater than 1 also works.
|
||||
m_spin->SetDigits(0);
|
||||
m_spin->SetIncrement(2.5);
|
||||
m_spin->SetValue(7.5);
|
||||
CHECK( m_spin->GetTextValue() == "7.5" );
|
||||
}
|
||||
|
||||
static inline unsigned int GetInitialDigits(double inc)
|
||||
|
Loading…
Reference in New Issue
Block a user