mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-15 15:16:47 +02:00
Fix a precision bug of valueToString, prevent to give an error result… (#1246)
* Fix a precision bug of valueToString, prevent to give an error result on input of wanted precision 0 and a double value which end of zero before decimal point ,such as 1230.01,12300.1; Add test cases for double valueToString with precision 0; * Delete a test case with platform differences in the previous commit * Fix clang-format. * Fix clang-format! Co-authored-by: lilei <dlilei@126.com>
This commit is contained in:
@@ -2005,6 +2005,34 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, precision) {
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 0;
|
||||
b.settings_["precisionType"] = "decimal";
|
||||
v = 123.56345694873740545068;
|
||||
expected = "124";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 1;
|
||||
b.settings_["precisionType"] = "decimal";
|
||||
v = 1230.001;
|
||||
expected = "1230.0";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 0;
|
||||
b.settings_["precisionType"] = "decimal";
|
||||
v = 1230.001;
|
||||
expected = "1230";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 0;
|
||||
b.settings_["precisionType"] = "decimal";
|
||||
v = 1231.5;
|
||||
expected = "1232";
|
||||
result = Json::writeString(b, v);
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||
|
||||
b.settings_["precision"] = 10;
|
||||
b.settings_["precisionType"] = "decimal";
|
||||
v = 0.23300000;
|
||||
|
Reference in New Issue
Block a user