Git Product home page Git Product logo

Comments (8)

erikdahlstrand avatar erikdahlstrand commented on June 15, 2024

I guess to_s is called on BigDecmials so instead of

json.(variant, :price, id)

I can use...

json.price variant.price.to_f
json.id    variant.id

from jbuilder.

sdepold avatar sdepold commented on June 15, 2024

I guess this should be fixed internally. Will give it a try. Imho the result should be a float-esque representation of the BigDecimal.

from jbuilder.

sdepold avatar sdepold commented on June 15, 2024

fixed: https://github.com/sdepold/jbuilder/blob/master/test/jbuilder_test.rb#L496

from jbuilder.

rwz avatar rwz commented on June 15, 2024
>> number = BigDecimal.new('1.23')
=> #<BigDecimal:7fb0e0b506d8,'0.123E1',18(18)>
>> number.to_json
=> "\"0.123E1\""
>> MultiJson.dump(number)
=> "\"0.123E1\""

from jbuilder.

uberllama avatar uberllama commented on June 15, 2024

Blast from the past, as I just ran into this again. Looks like it was fixed in a fork but never merged into master? You should definitely not have to explicitly cast a decimal to a float.

from jbuilder.

sdepold avatar sdepold commented on June 15, 2024

The respective pull request was rejected.

from jbuilder.

besi avatar besi commented on June 15, 2024

The pull request is #80

from jbuilder.

rwz avatar rwz commented on June 15, 2024

JSON spec does not introduce any limits for floats or integers, but JavaScript engines that are used to parse this do. For instance JavaScript floats are represented with 64 bits, and integers only have 32 iirc.

So, Ruby's Bignum can theoretically be properly encoded into JSON, but none of the existing JavaScript engines would be able to parse it correctly. And Ruby's JSON and ActiveSupport tend to make it JavaScript compatible in the first place.

If you're absolutely sure your BigNums aren't gonna overflow, cast them to integers or floats before passing to Jbuilder.

from jbuilder.

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.