Skip to content

Commit 8f6f084

Browse files
author
minium
committed
Fixed double imprecisionness issue. Properly.
1 parent 55c8ed1 commit 8f6f084

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/bitcoinapi/bitcoinapi.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using std::vector;
3232

3333

3434
BitcoinAPI::BitcoinAPI(const string& user, const string& password, const string& host, int port)
35-
: httpClient(new HttpClient("http://" + user + ":" + password + "@" + host + ":" + NumberToString(port))),
35+
: httpClient(new HttpClient("http://" + user + ":" + password + "@" + host + ":" + IntegerToString(port))),
3636
client(new Client(*httpClient, JSONRPC_CLIENT_V1))
3737
{
3838
httpClient->SetTimeout(50000);
@@ -44,27 +44,28 @@ BitcoinAPI::~BitcoinAPI()
4444
delete httpClient;
4545
}
4646

47-
string BitcoinAPI::NumberToString (int number){
47+
string BitcoinAPI::IntegerToString(int num){
4848
std::ostringstream ss;
49-
ss << number;
49+
ss << num;
5050
return ss.str();
5151
}
5252

53-
int BitcoinAPI::StringToNumber (const string &text){
54-
std::istringstream ss(text);
55-
int result;
56-
return ss >> result ? result : 0;
57-
}
58-
59-
double BitcoinAPI::RoundDouble(double num)
53+
std::string BitcoinAPI::RoundDouble(double num)
6054
{
61-
return floor(num * pow(10,8)) / pow(10,8);
55+
std::ostringstream ss;
56+
ss.precision(16);
57+
58+
ss << num;
59+
return ss.str();
6260
}
6361

6462
Value BitcoinAPI::sendcommand(const string& command, const Value& params){
6563
Value result;
6664

6765
try{
66+
std::cout << "DEBUG:" << std::endl;
67+
std::cout << params << std::endl;
68+
6869
result = client->CallMethod(command, params);
6970
}
7071
catch (JsonRpcException& e){

src/bitcoinapi/bitcoinapi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class BitcoinAPI
3030

3131
/* === Auxiliary functions === */
3232
Json::Value sendcommand(const std::string& command, const Json::Value& params);
33-
std::string NumberToString(int num);
34-
int StringToNumber(const std::string& str);
35-
double RoundDouble(double num);
33+
34+
std::string IntegerToString(int num);
35+
std::string RoundDouble(double num);
3636

3737

3838
/* === Node functions === */

0 commit comments

Comments
 (0)