12
12
13
13
#include < string>
14
14
#include < stdexcept>
15
+ #include < cmath>
15
16
16
17
#include < jsonrpccpp/client.h>
17
18
#include < jsonrpccpp/client/connectors/httpclient.h>
@@ -55,6 +56,11 @@ int BitcoinAPI::StringToNumber (const string &text){
55
56
return ss >> result ? result : 0 ;
56
57
}
57
58
59
+ double BitcoinAPI::RoundDouble (double num)
60
+ {
61
+ return floor (num * pow (10 ,8 )) / pow (10 ,8 );
62
+ }
63
+
58
64
Value BitcoinAPI::sendcommand (const string& command, const Value& params){
59
65
Value result;
60
66
@@ -372,7 +378,7 @@ void BitcoinAPI::keypoolrefill() {
372
378
bool BitcoinAPI::settxfee (double amount) {
373
379
string command = " settxfee" ;
374
380
Value params, result;
375
- params.append (amount);
381
+ params.append (RoundDouble ( amount) );
376
382
result = sendcommand (command, params);
377
383
return result.asBool ();
378
384
}
@@ -701,7 +707,7 @@ bool BitcoinAPI::move(const string& fromaccount, const string& toaccount, double
701
707
702
708
params.append (fromaccount);
703
709
params.append (toaccount);
704
- params.append (amount);
710
+ params.append (RoundDouble ( amount) );
705
711
params.append (minconf);
706
712
result = sendcommand (command, params);
707
713
@@ -714,7 +720,7 @@ bool BitcoinAPI::move(const string& fromaccount, const string& toaccount, double
714
720
715
721
params.append (fromaccount);
716
722
params.append (toaccount);
717
- params.append (amount);
723
+ params.append (RoundDouble ( amount) );
718
724
params.append (minconf);
719
725
params.append (comment);
720
726
result = sendcommand (command, params);
@@ -737,7 +743,7 @@ string BitcoinAPI::sendtoaddress(const string& bitcoinaddress, double amount) {
737
743
Value params, result;
738
744
739
745
params.append (bitcoinaddress);
740
- params.append (amount);
746
+ params.append (RoundDouble ( amount) );
741
747
742
748
result = sendcommand (command, params);
743
749
return result.asString ();
@@ -748,7 +754,7 @@ string BitcoinAPI::sendtoaddress(const string& bitcoinaddress, double amount, co
748
754
Value params, result;
749
755
750
756
params.append (bitcoinaddress);
751
- params.append (amount);
757
+ params.append (RoundDouble ( amount) );
752
758
params.append (comment);
753
759
params.append (comment_to);
754
760
@@ -762,7 +768,7 @@ string BitcoinAPI::sendfrom(const string& fromaccount, const string& tobitcoinad
762
768
763
769
params.append (fromaccount);
764
770
params.append (tobitcoinaddress);
765
- params.append (amount);
771
+ params.append (RoundDouble ( amount) );
766
772
767
773
result = sendcommand (command, params);
768
774
return result.asString ();
@@ -774,7 +780,7 @@ string BitcoinAPI::sendfrom(const string& fromaccount, const string& tobitcoinad
774
780
775
781
params.append (fromaccount);
776
782
params.append (tobitcoinaddress);
777
- params.append (amount);
783
+ params.append (RoundDouble ( amount) );
778
784
params.append (minconf);
779
785
params.append (comment);
780
786
params.append (comment_to);
@@ -791,7 +797,7 @@ string BitcoinAPI::sendmany(const string& fromaccount, const map<string,double>&
791
797
792
798
Value obj (Json::objectValue);
793
799
for (map<string,double >::const_iterator it = amounts.begin (); it != amounts.end (); it++){
794
- obj[(*it).first ] = ( *it).second ;
800
+ obj[(*it).first ] = RoundDouble (( *it).second ) ;
795
801
}
796
802
797
803
params.append (obj);
@@ -808,7 +814,7 @@ string BitcoinAPI::sendmany(const string& fromaccount, const map<string,double>&
808
814
809
815
Value obj (Json::objectValue);
810
816
for (map<string,double >::const_iterator it = amounts.begin (); it != amounts.end (); it++){
811
- obj[(*it).first ] = ( *it).second ;
817
+ obj[(*it).first ] = RoundDouble (( *it).second ) ;
812
818
}
813
819
814
820
params.append (obj);
@@ -1156,7 +1162,7 @@ string BitcoinAPI::createrawtransaction(const vector<txout_t>& inputs, const map
1156
1162
1157
1163
Value obj (Json::objectValue);
1158
1164
for (map<string,double >::const_iterator it = amounts.begin (); it != amounts.end (); it++){
1159
- obj[(*it).first ] = ( *it).second ;
1165
+ obj[(*it).first ] = RoundDouble (( *it).second ) ;
1160
1166
}
1161
1167
1162
1168
params.append (vec);
0 commit comments