Skip to content

Commit

Permalink
fix(util/gconv): fix missing minus in string to int64 conversion (#3920)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleChair authored Nov 13, 2024
1 parent 6baf433 commit ffa6081
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions util/gconv/gconv_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func Int64(any interface{}) int64 {
if valueInt64 := Float64(s); math.IsNaN(valueInt64) {
return 0
} else {
if isMinus {
return -int64(valueInt64)
}
return int64(valueInt64)
}
default:
Expand Down
1 change: 1 addition & 0 deletions util/gconv/gconv_z_unit_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var intTests = []struct {
{"0XA", 10, 10, 10, 10, 10},
{"-0XA", -10, -10, -10, -10, -10},
{"123.456", 123, 123, 123, 123, 123},
{"-123.456", -123, -123, -123, -123, -123},
{"true", 0, 0, 0, 0, 0},
{"false", 0, 0, 0, 0, 0},
{"on", 0, 0, 0, 0, 0},
Expand Down

0 comments on commit ffa6081

Please sign in to comment.