stretchr / objx

Go package for dealing with maps, slices, JSON and other data.
MIT License
687 stars 75 forks source link

Float conversion behavior issue #101

Closed naueramant closed 2 years ago

naueramant commented 3 years ago

Since i upgraded the package to 0.3.0 from 0.1.1 i have noticed that the behavior of the float conversion have changed. An example:

package main

import (
    "fmt"
    "github.com/stretchr/objx"
)

func main() {
    m1 := objx.MustFromJSON(`{"foo": 1500.0}`)
    foo1 := m1.Get("foo").Float64(-1)
    fmt.Println(foo1)

    m2 := objx.MustFromJSON(`{"foo": 1500.1}`)
    foo2 := m2.Get("foo").Float64(-1)
    fmt.Println(foo2)
}

Output:

-1
1500.1

Go playground: https://play.golang.org/p/BU-r9HkEZHE

Expected behavior should be that also 1500.0 even 1500 should be seen as a float and therefor not return the default value. One would expect that only non numerical values would return -1 in this example.

valerius21 commented 3 years ago

I am having the same issue with Float32