I'm trying to parse latitude and longitude from a json object with precision, and I picked float64 for the job. However float64 is somehow rounding the number and I'm not sure what to do in order to avoid rounding.
I've created a quick snippet so you can execute the problem: http://play.golang.org/p/9g6Imn-7GK
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type Position struct {
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
}
func main() {
s := `{"lat":13.519004709972312,"lon": -13.519004709972312}`
pos := Position{}
json.Unmarshal([]byte(s), &pos)
if !reflect.DeepEqual(s, &pos) {
fmt.Printf("\nExpected %#v\nbut got %#v", s, pos)
}
}
math/big
if you want higher precision than float64.json.Number
may be of some use.float64
, but your input has 17.