Remove std::to_string(double), due to fixed conversion precision

- std::to_string(double) converts double to precision 6, eg 1 to "1.000000"
- stringstream conversion from double to string will keep minimal
  number of decimals (eg, it wil ltrim zeros), eg 1 to "1", 1.2 to "1.2"
This commit is contained in:
serkixenos 2020-12-02 01:23:07 +01:00
parent f532386567
commit 24670d7c5c

View file

@ -5561,8 +5561,15 @@ signed_transaction wallet_api::sell( string seller_account,
double amount,
bool broadcast )
{
return my->sell_asset( seller_account, std::to_string( amount ), base,
std::to_string( rate * amount ), quote, 0, false, broadcast );
std::stringstream ss;
ss.str(std::string());
ss << std::noshowpoint << amount;
std::string amount_to_sell = ss.str();
ss.str(std::string());
ss << std::noshowpoint << rate * amount;
std::string min_to_receive = ss.str();
return my->sell_asset( seller_account, amount_to_sell, base,
min_to_receive, quote, 0, false, broadcast );
}
signed_transaction wallet_api::buy( string buyer_account,
@ -5572,8 +5579,15 @@ signed_transaction wallet_api::buy( string buyer_account,
double amount,
bool broadcast )
{
return my->sell_asset( buyer_account, std::to_string( rate * amount ), quote,
std::to_string( amount ), base, 0, false, broadcast );
std::stringstream ss;
ss.str(std::string());
ss << std::noshowpoint << rate * amount;
std::string amount_to_sell = ss.str();
ss.str(std::string());
ss << std::noshowpoint << amount;
std::string min_to_receive = ss.str();
return my->sell_asset( buyer_account, amount_to_sell, quote,
min_to_receive, base, 0, false, broadcast );
}
signed_transaction wallet_api::borrow_asset(string seller_name, string amount_to_sell,