Handle $ and , in amount

This commit is contained in:
2024-12-17 21:07:23 -05:00
parent 5a39ade237
commit fc228d329e

12
main.go
View File

@@ -84,7 +84,7 @@ type Transaction struct {
type TransactionYaml struct {
Name string `yaml:"name"`
Amount float64 `yaml:"amount"`
Amount string `yaml:"amount"`
Date string `yaml:"date"`
Delayable string `yaml:"delayable"`
Frequency string `yaml:"frequency,omitempty"`
@@ -204,8 +204,16 @@ func parseTransaction(transactionYaml TransactionYaml) (*Transaction, error) {
return nil, err
}
amountStr := strings.ReplaceAll(transactionYaml.Amount, "$", "")
amountStr = strings.ReplaceAll(amountStr, ",", "")
amount, err := strconv.ParseFloat(amountStr, 32)
if err != nil {
return nil, err
}
transaction := &Transaction{
Amount: transactionYaml.Amount,
Amount: amount,
Date: stripTime(date),
Delayable: delayable,
Frequency: transactionYaml.Frequency,