Skip to content

Commit

Permalink
Fix 修复超出10000,金额变成科学计数法
Browse files Browse the repository at this point in the history
  • Loading branch information
aimuz committed Nov 15, 2018
1 parent 2b1e526 commit cb60985
Showing 1 changed file with 46 additions and 10 deletions.
56 changes: 46 additions & 10 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,57 @@ func Struct2Map(r interface{}) (s map[string]string, err error) {
return nil, err
}
for k, v := range temp {
switch v2 := v.(type) {
case string:
result[k] = v2
break
case int8, uint8, int, uint, int32, uint32, int64, uint64:
result[k] = fmt.Sprint(v2)
break
case float32, float64:
result[k] = fmt.Sprint(v2)
break
result[k], err = ToStringE(v)
if err != nil {
return nil, err
}
}
return result, nil
}

func ToStringE(i interface{}) (string, error) {
switch s := i.(type) {
case string:
return s, nil
case bool:
return strconv.FormatBool(s), nil
case float64:
return strconv.FormatFloat(s, 'f', -1, 64), nil
case float32:
return strconv.FormatFloat(float64(s), 'f', -1, 32), nil
case int:
return strconv.Itoa(s), nil
case int64:
return strconv.FormatInt(s, 10), nil
case int32:
return strconv.Itoa(int(s)), nil
case int16:
return strconv.FormatInt(int64(s), 10), nil
case int8:
return strconv.FormatInt(int64(s), 10), nil
case uint:
return strconv.FormatInt(int64(s), 10), nil
case uint64:
return strconv.FormatInt(int64(s), 10), nil
case uint32:
return strconv.FormatInt(int64(s), 10), nil
case uint16:
return strconv.FormatInt(int64(s), 10), nil
case uint8:
return strconv.FormatInt(int64(s), 10), nil
case []byte:
return string(s), nil
case nil:
return "", nil
case fmt.Stringer:
return s.String(), nil
case error:
return s.Error(), nil
default:
return "", fmt.Errorf("unable to cast %#v of type %T to string", i, i)
}
}

// GenWeChatPaySign 生成微信签名
func GenWeChatPaySign(m map[string]string, payKey string) (string, error) {
delete(m, "sign")
Expand Down

0 comments on commit cb60985

Please sign in to comment.