Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float conversion behavior issue #101

Closed
naueramant opened this issue Jan 13, 2021 · 1 comment · Fixed by #108
Closed

Float conversion behavior issue #101

naueramant opened this issue Jan 13, 2021 · 1 comment · Fixed by #108

Comments

@naueramant
Copy link

naueramant commented Jan 13, 2021

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
Copy link

I am having the same issue with Float32

@naueramant naueramant changed the title Float64 conversion issue Float conversion issue Feb 8, 2021
@naueramant naueramant changed the title Float conversion issue Float conversion behavior issue Feb 8, 2021
@geseq geseq mentioned this issue Jul 3, 2021
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants