Added precision parameter to wxString::From[C]Double().
Optionally support fixed precision in wxString::FromDouble() and FromCDouble() methods. This is mostly useful for the latter to be able to format numbers in portable way (using dot as decimal separator) without loss of precision but also do it for the former for consistency. Closes #12973. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67181 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -762,25 +762,30 @@ void StringTestCase::FromDouble()
|
||||
static const struct FromDoubleTestData
|
||||
{
|
||||
double value;
|
||||
int prec;
|
||||
const char *str;
|
||||
} testData[] =
|
||||
{
|
||||
{ 1.23, "1.23" },
|
||||
{ 1.23, -1, "1.23" },
|
||||
// NB: there are no standards about the minimum exponent width
|
||||
// and newer MSVC versions use 3 digits as minimum exponent
|
||||
// width while GNU libc uses 2 digits as minimum width...
|
||||
#ifdef wxUSING_VC_CRT_IO
|
||||
{ -3e-10, "-3e-010" },
|
||||
{ -3e-10, -1, "-3e-010" },
|
||||
#else
|
||||
{ -3e-10, "-3e-10" },
|
||||
{ -3e-10, -1, "-3e-10" },
|
||||
#endif
|
||||
{ -0.45678, "-0.45678" },
|
||||
{ -0.45678, -1, "-0.45678" },
|
||||
{ 1.2345678, 0, "1" },
|
||||
{ 1.2345678, 1, "1.2" },
|
||||
{ 1.2345678, 2, "1.23" },
|
||||
{ 1.2345678, 3, "1.235" },
|
||||
};
|
||||
|
||||
for ( unsigned n = 0; n < WXSIZEOF(testData); n++ )
|
||||
{
|
||||
const FromDoubleTestData& td = testData[n];
|
||||
CPPUNIT_ASSERT_EQUAL( td.str, wxString::FromCDouble(td.value) );
|
||||
CPPUNIT_ASSERT_EQUAL( td.str, wxString::FromCDouble(td.value, td.prec) );
|
||||
}
|
||||
|
||||
if ( !wxLocale::IsAvailable(wxLANGUAGE_FRENCH) )
|
||||
@@ -795,7 +800,7 @@ void StringTestCase::FromDouble()
|
||||
|
||||
wxString str(td.str);
|
||||
str.Replace(".", ",");
|
||||
CPPUNIT_ASSERT_EQUAL( str, wxString::FromDouble(td.value) );
|
||||
CPPUNIT_ASSERT_EQUAL( str, wxString::FromDouble(td.value, td.prec) );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user