修正gconv包float32->float64精度问题

This commit is contained in:
john
2018-06-27 20:58:28 +08:00
parent 90b440a6ea
commit 9af4f95982
3 changed files with 8 additions and 7 deletions

View File

@ -106,7 +106,7 @@ func String(i interface{}) string {
case uint16: return strconv.FormatUint(uint64(value), 10)
case uint32: return strconv.FormatUint(uint64(value), 10)
case uint64: return strconv.FormatUint(uint64(value), 10)
case float32: return strconv.FormatFloat(float64(value), 'f', -1, 64)
case float32: return strconv.FormatFloat(float64(value), 'f', -1, 32)
case float64: return strconv.FormatFloat(value, 'f', -1, 64)
case bool: return strconv.FormatBool(value)
case string: return value
@ -289,7 +289,7 @@ func Float32 (i interface{}) float32 {
if v, ok := i.(float32); ok {
return v
}
v, _ := strconv.ParseFloat(String(i), 32)
v, _ := strconv.ParseFloat(String(i), 64)
return float32(v)
}

View File

@ -9,7 +9,7 @@ import (
)
func main() {
clientMax := 10
clientMax := 1000
requestMax := 1000
failureNum := gtype.NewInt64()
successNum := gtype.NewInt64()
@ -21,7 +21,7 @@ func main() {
go func(clientId int) {
url := "http://127.0.0.1:8199/"
for i := 0; i < requestMax; i++ {
url = fmt.Sprintf("http://127.0.0.1:8199/%d_%d", clientId, i)
//url = fmt.Sprintf("http://127.0.0.1:8199/%d_%d", clientId, i)
if c, e := ghttp.Get(url); e == nil {
c.Close()
successNum.Add(1)

View File

@ -1,11 +1,12 @@
package main
import (
"time"
"fmt"
"gitee.com/johng/gf/g/util/gconv"
)
func main() {
t := time.Now().Zone()
fmt.Println(z)
fmt.Println(gconv.Float64(float32(19.66)))
fmt.Println(float64(float32(19.66)))
}