Improve formatting of profit columns

pull/243/head
Simon Roberts 3 years ago
parent 2aa798b3fa
commit 90187d88b5
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -346,8 +346,7 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
costPrice, err := ct.Convert(coin.BuyCurrency, ct.State.currencyConversion, coin.BuyPrice)
if err == nil {
profit := (coin.Price - costPrice) * coin.Holdings
profit = math.Round(100*profit) / 100 // cheesy round
text = ct.FormatPrice(profit)
text = humanize.FixedMonetaryf(profit, 2)
} else {
text = "?"
}

@ -231,7 +231,7 @@ func (ct *Cointop) UpdateTableHeader() error {
}
leftAlign := ct.GetTableColumnAlignLeft(col)
switch col {
case "price", "balance":
case "price", "balance", "profit":
label = fmt.Sprintf("%s%s", ct.CurrencySymbol(), label)
}
if leftAlign {

@ -34,6 +34,11 @@ func Monetaryf(value float64, precision int) string {
return f(value, precision, "LC_MONETARY", false)
}
// FixedMonetaryf produces a fixed-precision monetary-value string. See Monetaryf.
func FixedMonetaryf(value float64, precision int) string {
return f(value, precision, "LC_MONETARY", true)
}
// borrowed from go-locale/util.go
func splitLocale(locale string) (string, string) {
// Remove the encoding, if present

Loading…
Cancel
Save