Handle 0 change case

This commit is contained in:
adityapk00
2018-11-24 08:17:46 -08:00
parent a2db1dc8a6
commit 7d6bf31caa
2 changed files with 7 additions and 2 deletions

View File

@@ -413,8 +413,10 @@ Tx MainWindow::createTxFromSendPage() {
if (saplingAddr != rpc->getAllZAddresses()->end()) {
double change = rpc->getAllBalances()->value(tx.fromAddr) - totalAmt - tx.fee;
QString changeMemo = "Change from " + tx.fromAddr;
tx.toAddrs.push_back( ToFields{*saplingAddr, change, changeMemo, changeMemo.toUtf8().toHex()} );
if (Settings::getDecimalString(change) != "0") {
QString changeMemo = "Change from " + tx.fromAddr;
tx.toAddrs.push_back(ToFields{ *saplingAddr, change, changeMemo, changeMemo.toUtf8().toHex() });
}
}
}

View File

@@ -143,9 +143,12 @@ QString Settings::getUSDFormat(double bal) {
QString Settings::getDecimalString(double amt) {
QString f = QString::number(amt, 'f', 8);
while (f.contains(".") && (f.right(1) == "0" || f.right(1) == ".")) {
f = f.left(f.length() - 1);
}
if (f == "-0")
f = "0";
return f;
}