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

How to solve precision problem in tengo? #379

Closed
yayakoBlessing opened this issue May 14, 2022 · 4 comments · Fixed by #399
Closed

How to solve precision problem in tengo? #379

yayakoBlessing opened this issue May 14, 2022 · 4 comments · Fixed by #399

Comments

@yayakoBlessing
Copy link

yayakoBlessing commented May 14, 2022

Hi, thanks for such a great project!

How to solve precision problem in tengo?

json := import("json")
fmt := import("fmt")


base_info := bytes(`{
        "1":7075984636689534001,
        "2":7075984636689534002
}`)
m := json.decode(base_info)
fmt.println(m[1])

result: 7075984636689534000

@geseq
Copy link
Collaborator

geseq commented May 19, 2022

I think this might be due to the Go json package parsing numbers as floats. I’m not sure you can do anything other than write a custom parser for your use case

@yayakoBlessing
Copy link
Author

Thanks for replying. Does Tengo support for custom parsers? Or should I realize it in another way.

@geseq
Copy link
Collaborator

geseq commented May 20, 2022

Tengo’s json parsing is built off of Go’s but yes you can fairly easily modify it and create your own json library. This might help you get started:

if c != '-' && (c < '0' || c > '9') {

@yayakoBlessing
Copy link
Author

Thanks, help me a lot!

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