Fix bug in wxNumberFormatter::ToString() for negative numbers.
Don't include the possible leading sign in the span of digits to be grouped as this gave nonsensical strings such as "-,123" when adding thousands separators to "123". Closes #14526. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72256 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -235,6 +235,10 @@ void wxNumberFormatter::AddThousandsSeparators(wxString& s)
|
|||||||
pos = s.length();
|
pos = s.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// End grouping at the beginning of the digits -- there could be at a sign
|
||||||
|
// before their start.
|
||||||
|
const size_t start = s.find_first_of("0123456789");
|
||||||
|
|
||||||
// We currently group digits by 3 independently of the locale. This is not
|
// We currently group digits by 3 independently of the locale. This is not
|
||||||
// the right thing to do and we should use lconv::grouping (under POSIX)
|
// the right thing to do and we should use lconv::grouping (under POSIX)
|
||||||
// and GetLocaleInfo(LOCALE_SGROUPING) (under MSW) to get information about
|
// and GetLocaleInfo(LOCALE_SGROUPING) (under MSW) to get information about
|
||||||
@@ -242,7 +246,7 @@ void wxNumberFormatter::AddThousandsSeparators(wxString& s)
|
|||||||
// wxLocale level first and then used here in the future (TODO).
|
// wxLocale level first and then used here in the future (TODO).
|
||||||
const size_t GROUP_LEN = 3;
|
const size_t GROUP_LEN = 3;
|
||||||
|
|
||||||
while ( pos > GROUP_LEN )
|
while ( pos > start + GROUP_LEN )
|
||||||
{
|
{
|
||||||
pos -= GROUP_LEN;
|
pos -= GROUP_LEN;
|
||||||
s.insert(pos, thousandsSep);
|
s.insert(pos, thousandsSep);
|
||||||
|
@@ -93,13 +93,21 @@ void NumFormatterTestCase::LongToString()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( "1", wxNumberFormatter::ToString( 1L));
|
CPPUNIT_ASSERT_EQUAL( "1", wxNumberFormatter::ToString( 1L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "-1", wxNumberFormatter::ToString( -1L));
|
||||||
CPPUNIT_ASSERT_EQUAL( "12", wxNumberFormatter::ToString( 12L));
|
CPPUNIT_ASSERT_EQUAL( "12", wxNumberFormatter::ToString( 12L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "-12", wxNumberFormatter::ToString( -12L));
|
||||||
CPPUNIT_ASSERT_EQUAL( "123", wxNumberFormatter::ToString( 123L));
|
CPPUNIT_ASSERT_EQUAL( "123", wxNumberFormatter::ToString( 123L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "-123", wxNumberFormatter::ToString( -123L));
|
||||||
CPPUNIT_ASSERT_EQUAL( "1,234", wxNumberFormatter::ToString( 1234L));
|
CPPUNIT_ASSERT_EQUAL( "1,234", wxNumberFormatter::ToString( 1234L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "-1,234", wxNumberFormatter::ToString( -1234L));
|
||||||
CPPUNIT_ASSERT_EQUAL( "12,345", wxNumberFormatter::ToString( 12345L));
|
CPPUNIT_ASSERT_EQUAL( "12,345", wxNumberFormatter::ToString( 12345L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "-12,345", wxNumberFormatter::ToString( -12345L));
|
||||||
CPPUNIT_ASSERT_EQUAL( "123,456", wxNumberFormatter::ToString( 123456L));
|
CPPUNIT_ASSERT_EQUAL( "123,456", wxNumberFormatter::ToString( 123456L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "-123,456", wxNumberFormatter::ToString( -123456L));
|
||||||
CPPUNIT_ASSERT_EQUAL( "1,234,567", wxNumberFormatter::ToString( 1234567L));
|
CPPUNIT_ASSERT_EQUAL( "1,234,567", wxNumberFormatter::ToString( 1234567L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "-1,234,567", wxNumberFormatter::ToString( -1234567L));
|
||||||
CPPUNIT_ASSERT_EQUAL( "12,345,678", wxNumberFormatter::ToString( 12345678L));
|
CPPUNIT_ASSERT_EQUAL( "12,345,678", wxNumberFormatter::ToString( 12345678L));
|
||||||
|
CPPUNIT_ASSERT_EQUAL("-12,345,678", wxNumberFormatter::ToString( -12345678L));
|
||||||
CPPUNIT_ASSERT_EQUAL("123,456,789", wxNumberFormatter::ToString( 123456789L));
|
CPPUNIT_ASSERT_EQUAL("123,456,789", wxNumberFormatter::ToString( 123456789L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user