From 24670d7c5c4ef4908146415ef583c62813290839 Mon Sep 17 00:00:00 2001 From: serkixenos Date: Wed, 2 Dec 2020 01:23:07 +0100 Subject: [PATCH] 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" --- libraries/wallet/wallet.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 98dc122c..74bf9bd4 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -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,