Use printf in template

This commit is contained in:
Jan Bader 2021-12-02 20:53:05 +00:00
parent 696469f6c2
commit a4659c7133
3 changed files with 5 additions and 7 deletions

View File

@ -116,7 +116,7 @@ func trimLastChar(s string) string {
} }
func GetAmount(inflow string, outflow string) (pgtype.Numeric, error) { func GetAmount(inflow string, outflow string) (pgtype.Numeric, error) {
// Remove currency // Remove trailing currency
inflow = strings.Replace(trimLastChar(inflow), ",", ".", 1) inflow = strings.Replace(trimLastChar(inflow), ",", ".", 1)
outflow = strings.Replace(trimLastChar(outflow), ",", ".", 1) outflow = strings.Replace(trimLastChar(outflow), ",", ".", 1)
@ -126,6 +126,7 @@ func GetAmount(inflow string, outflow string) (pgtype.Numeric, error) {
return num, fmt.Errorf("Could not parse inflow %s: %w", inflow, err) return num, fmt.Errorf("Could not parse inflow %s: %w", inflow, err)
} }
// if inflow is zero, use outflow
if num.Int.Int64() != 0 { if num.Int.Int64() != 0 {
return num, nil return num, nil
} }

View File

@ -44,11 +44,6 @@ func (tx Transaction) GetAmount() float64 {
return amount return amount
} }
func (tx Transaction) GetAmountString() string {
amount := tx.GetAmount()
return fmt.Sprintf("%.2f", amount)
}
func (tx Transaction) GetPositive() bool { func (tx Transaction) GetPositive() bool {
amount := tx.GetAmount() amount := tx.GetAmount()
return amount >= 0 return amount >= 0

View File

@ -19,7 +19,9 @@
<td> <td>
<a href="transaction/{{.ID}}">{{.Memo}}</a> <a href="transaction/{{.ID}}">{{.Memo}}</a>
</td> </td>
<td style="text-align: right;{{if .GetPositive()}}{{else}}color: red;{{end}}">{{.GetAmount}}</td> <td style="text-align: right;{{if .GetPositive}}{{else}}color: red;{{end}}">
{{printf "%.2f" .GetAmount}}
</td>
</tr> </tr>
{{end}} {{end}}
</table> </table>