How to solve precision problem in tengo?
yayakoBlessing opened this issue · 4 comments
yayakoBlessing commented
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 commented
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 commented
Thanks for replying. Does Tengo support for custom parsers? Or should I realize it in another way.
geseq commented
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:
Line 210 in f90d433
yayakoBlessing commented
Thanks, help me a lot!