Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions j5types/decimal_j5t/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/shopspring/decimal"
)

var reDecimal = regexp.MustCompile(`^-?\d+(\.\d+)?$`)
var reDecimal = regexp.MustCompile(`^-?\d*(\.\d+)?$`)

func (d *Decimal) ToShop() (decimal.Decimal, error) {
return decimal.NewFromString(d.Value)
Expand All @@ -19,7 +19,12 @@ func (dd *Decimal) UnmarshalText(data []byte) error {
return fmt.Errorf("invalid decimal format: %s", string(data))
}

dd.Value = str
d, err := decimal.NewFromString(str)
if err != nil {
return fmt.Errorf("error converting %s to decimal: %v", string(data), err)
}

dd.Value = d.String()
return nil
}

Expand Down Expand Up @@ -132,7 +137,14 @@ type Testing interface {
Errorf(format string, args ...any)
}

type helper interface {
Helper()
}

func AssertEqual(t Testing, want string, d1 *Decimal, name string) {
if h, ok := t.(helper); ok {
h.Helper()
}
dWant, err := decimal.NewFromString(want)
if err != nil {
t.Errorf("%s: error converting want %s to decimal: %v", name, want, err)
Expand Down
Loading