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

Cannot decode integers into floats #835

Closed
horgh opened this issue Dec 23, 2022 · 2 comments
Closed

Cannot decode integers into floats #835

horgh opened this issue Dec 23, 2022 · 2 comments

Comments

@horgh
Copy link

horgh commented Dec 23, 2022

Describe the bug
I have a config with entries like

foo = 5

And I would like to decode them into a float64. This errors with: toml: cannot decode TOML integer into struct field main.conf.Foo of type float64

To Reproduce

package main

import (
        "log"

        toml "github.com/pelletier/go-toml/v2"
)

func main() {
        type conf struct {
                Foo float64 `json:"foo"`
        }
        var c conf

        buf := []byte(`foo = 5`)

        if err := toml.Unmarshal(buf, &c); err != nil {
                log.Fatal(err)
        }
        log.Printf("%+v", c)
}

Expected behavior
I think it would be good to be able to deserialize ints into floats. encoding/json works that way for instance.

Versions

  • go-toml: github.com/pelletier/go-toml/v2 v2.0.6
  • go: go version go1.19.4 linux/amd64
  • operating system: Linux

Additional context
I could write the config values as 5.0 to get around this. However the same config is also used by a Perl parser, which has a different issue when expressing numbers as 5.0. It would be helpful in my case to be able to leave it as "5".

Thank you!

@pelletier
Copy link
Owner

This should be fixed as of 9f57260. Feel free to reopen if it doesn't solve your problem!

@horgh
Copy link
Author

horgh commented Feb 10, 2023

Thank you!

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

No branches or pull requests

2 participants