Skip to content

Commit

Permalink
handle negative decimals missing whole part
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Nov 10, 2023
1 parent 43dba38 commit 4cdd173
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion decimal/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func NewFromString(s string) (Decimal, error) {
if whole, frac, split := strings.Cut(s, "."); split {
var neg bool
var w int64
if whole != "" {
if whole == "-" {
neg = true
} else if whole != "" {
var err error
neg, w, err = atoi64(whole)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions decimal/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ var testParseCases = []testCase{
"0.50",
".50",
},
{
"negmissingwhole",
"-0.50",
"-.50",
},
}

func TestStringParse(t *testing.T) {
Expand Down

0 comments on commit 4cdd173

Please sign in to comment.