GithubHelp home page GithubHelp logo

Decoding large integers. about null HOT 3 CLOSED

guregu avatar guregu commented on August 20, 2024
Decoding large integers.

from null.

Comments (3)

guregu avatar guregu commented on August 20, 2024

Hello, thank you for the kind words.

null.Float/zero.Float and would be the closest thing to Javascript numbers, and should support scientific notation.

Just making sure: are you numbers within the range of Go's int64 and just happen to be in scientific notation, or are your numbers larger than int64 can handle?

Go's encoding/json package dislikes scientific notation in any integer, even if it's a small number: http://play.golang.org/p/u_Am5XoPJW
Seems like a bug to me, to be honest...

Did you add support for something like big.Int?
Either way, I would be happy to include your code.

from null.

juandiegopalomino avatar juandiegopalomino commented on August 20, 2024

Hi guregu,
So upon further investigation, it seems that my issue stemmed from first unmarshalling the json to a map[string]interface{}, which automatically writes numbers in scientific notation. Sorry about that. The solution I wrote was basically, if unmarshalling to an int64 failed, then try unmarshalling it to a float64, and using that number if it's a valid int64 (I check that it doesn't have decimals, and is within the int64 range). If you're still interested, I'll be happy to supply you the small fix (it's only 10 lines). Thank you for your time, and have a nice day!

from null.

guregu avatar guregu commented on August 20, 2024

I'll keep things as-is for now, but thanks for the input.

from null.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.