Skip to content

Float conversion behavior issue #101

@naueramant

Description

@naueramant

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions