[
https://issues.apache.org/jira/browse/THRIFT-3636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15148007#comment-15148007
]
ASF GitHub Bot commented on THRIFT-3636:
----------------------------------------
Github user mygityf commented on a diff in the pull request:
https://github.com/apache/thrift/pull/870#discussion_r52961339
--- Diff: lib/cpp/src/thrift/protocol/TJSONProtocol.cpp ---
@@ -524,7 +524,8 @@ namespace {
std::string doubleToString(double d) {
std::ostringstream str;
str.imbue(std::locale::classic());
- str.precision(std::numeric_limits<double>::digits10 + 1);
+ // new precision is 17 equal to max_digits10(c++11) or digits10+2
+ str.precision(17);
--- End diff --
It looks better than before.
Thanks.
> The precision is 15 bits after dot of casting from double to string in
> Thrift-cpp-library- json-protocol.
> ---------------------------------------------------------------------------------------------------------
>
> Key: THRIFT-3636
> URL: https://issues.apache.org/jira/browse/THRIFT-3636
> Project: Thrift
> Issue Type: Bug
> Components: C++ - Library
> Affects Versions: 0.9.3
> Environment: Linux Mac Windows
> Reporter: WangYaofu
> Assignee: WangYaofu
> Fix For: 0.9.4
>
>
> The precision is 15 bits after dot of format casting from double to string in
> Thrift-cpp-library- json-protocol.
> But the expected precision is 16 bits after dot in Thrift-json-protocol.
> The solution:
> To Change code 'str.precision(std::numeric_limits<double>::digits10 + 1);' to
> 'str.precision(std::numeric_limits<double>::digits10 + 2);'
> in function doubeToString file TJSONProtocol.cpp at line 524,
> e.g:
> before:
> In C++ TJsonProtocol.cpp:
> double a = 1.12345678906666663;
> string astr = doubleToString(a);
> double b = stringToDouble(astr);
> the result as below:
> a = 1.1234567890666667
> astr = "1.123456789066667"
> b = 1.1234567890666669
> after changing:
> the result as below:
> a = 1.1234567890666667
> astr = "1.1234567890666667"
> b = 1.1234567890666667
> This result is expected.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)