-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
Sample:
package main
import (
"fmt"
"strconv"
"github.com/xiam/to"
)
func main() {
fmt.Println(to.Int64(35.24))//Expects 35; Received: 35
fmt.Println(to.Int(35.24))//Expect 35; Received: 35
fmt.Println(to.Int64("35.24")) //Expect 35; Received: 0
fmt.Println(to.Int("35.24")) //Expect 35; Received: 0
//Potential fix: use `strconv.ParseFloat` instead of `ParseInt`
i, _ := strconv.ParseFloat("35.24", 64)
fmt.Println(to.Int(i))
}
Context: Some client behavior in my application was truncating the floating value and converting to ints before sending it to my server. Was trying to make it such that the client now didn't bother to truncate and directly would send the float, as I was not expecting this library's code to treat strings differently than it did regular floats.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels