1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fmt: fix some gofmt issue

This commit is contained in:
dudaodong
2021-11-29 13:01:46 +08:00
parent 4848647918
commit 0c4b512084
14 changed files with 46 additions and 44 deletions

View File

@@ -14,4 +14,4 @@ func Comma(v interface{}, symbol string) string {
return symbol + commaString(s[:dotIndex]) + s[dotIndex:]
}
return symbol + commaString(s)
}
}

View File

@@ -1,25 +1,26 @@
package formatter
import (
"github.com/duke-git/lancet/utils"
"testing"
"github.com/duke-git/lancet/utils"
)
func TestComma(t *testing.T) {
comma(t, "", "","")
comma(t, "aa", "","")
comma(t, "123", "","123")
comma(t, "12345", "","12,345")
comma(t, 12345, "","12,345")
comma(t, 12345, "$","$12,345")
comma(t, 12345, "¥","¥12,345")
comma(t, 12345.6789, "","12,345.6789")
comma(t, "", "", "")
comma(t, "aa", "", "")
comma(t, "123", "", "123")
comma(t, "12345", "", "12,345")
comma(t, 12345, "", "12,345")
comma(t, 12345, "$", "$12,345")
comma(t, 12345, "¥", "¥12,345")
comma(t, 12345.6789, "", "12,345.6789")
}
func comma(t *testing.T, test interface{}, symbol string, expected interface{}) {
res:= Comma(test, symbol)
func comma(t *testing.T, test interface{}, symbol string, expected interface{}) {
res := Comma(test, symbol)
if res != expected {
utils.LogFailedTestInfo(t, "Comma", test, expected, res)
t.FailNow()
}
}
}

View File

@@ -18,22 +18,23 @@ func numString(value interface{}) string {
switch reflect.TypeOf(value).Kind() {
case reflect.Int, reflect.Int64, reflect.Float32, reflect.Float64:
return fmt.Sprintf("%v", value)
case reflect.String: {
sv := fmt.Sprintf("%v", value)
if strings.Contains(sv, ".") {
_, err := strconv.ParseFloat(sv, 64)
if err == nil {
return sv
}
}else {
_, err := strconv.ParseInt(sv, 10, 64)
if err == nil {
return sv
case reflect.String:
{
sv := fmt.Sprintf("%v", value)
if strings.Contains(sv, ".") {
_, err := strconv.ParseFloat(sv, 64)
if err == nil {
return sv
}
} else {
_, err := strconv.ParseInt(sv, 10, 64)
if err == nil {
return sv
}
}
}
}
default:
return ""
}
return ""
}
}