Poco::NumberFormatter::format(float, precision) rounding changed #1128

This commit is contained in:
Alex Fabijanic
2016-02-28 22:59:29 -06:00
parent 86657f38f4
commit 14a0872556
3 changed files with 62 additions and 1 deletions

View File

@@ -686,6 +686,28 @@ void StringTest::testStringToDouble()
}
void StringTest::testNumericStringPadding()
{
std::string str;
assert (floatToStr(str, 0.999f, 2, 4) == "1.00");
assert (floatToStr(str, 0.945f, 2, 4) == "0.95");
assert (floatToStr(str, 0.944f, 2, 4) == "0.94");
assert (floatToStr(str, 12.45f, 2, 5) == "12.45");
assert (floatToStr(str, 12.45f, 1, 4) == "12.5");
assert (floatToStr(str, 12.45f, 2, 6) == " 12.45");
assert (floatToStr(str, 12.455f, 3, 7) == " 12.455");
assert (floatToStr(str, 12.455f, 2, 6) == " 12.46");
assert (doubleToStr(str, 0.999, 2, 4) == "1.00");
assert (doubleToStr(str, 0.945, 2, 4) == "0.95");
assert (doubleToStr(str, 0.944, 2, 4) == "0.94");
assert (doubleToStr(str, 12.45, 2, 5) == "12.45");
assert (doubleToStr(str, 12.45, 1, 4) == "12.5");
assert (doubleToStr(str, 12.45, 2, 6) == " 12.45");
assert (floatToStr(str, 12.455f, 3, 7) == " 12.455");
assert (floatToStr(str, 12.455f, 2, 6) == " 12.46");
}
void StringTest::testStringToFloatError()
{
char ds = decimalSeparator();
@@ -1166,6 +1188,7 @@ CppUnit::Test* StringTest::suite()
CppUnit_addTest(pSuite, StringTest, testStringToInt);
CppUnit_addTest(pSuite, StringTest, testStringToFloat);
CppUnit_addTest(pSuite, StringTest, testStringToDouble);
CppUnit_addTest(pSuite, StringTest, testNumericStringPadding);
CppUnit_addTest(pSuite, StringTest, testStringToFloatError);
CppUnit_addTest(pSuite, StringTest, testNumericLocale);
//CppUnit_addTest(pSuite, StringTest, benchmarkStrToFloat);