Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Output formatting differences between jRuby 10.0.0.1 and Ruby 3.4 when converting Float to JSON.

Aperta
#817 3 commenti 1 reazione 1 assegnatario Vedi su GitHub

@headius ci sta già lavorando.

Dal 25/8/2025.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

jruby

In Ruby 3.4, when converting a Float value to JSON using .to_json, the output notation is more or less preserved. Namely, if your value is in scientific notation, the output will be in scientific notation. If it's decimal, it will remain decimal, though there does appear to be a precision limit where it will truncate additional decimals.

In jRuby 10.0.0.1, Float values above a certain size will always be converted to scientific notation in the output. The precision doesn't appear to be the culprit, it seems to be the number of digits to the LEFT of the decimal that determines this. If there are more than 7, it will convert the notation.

For example (in jRuby 10):

irb(main):001> x = 1234567.1234567893
=> 1234567.1234567894
irb(main):002> x.to_json
=> "1234567.1234567894"
irb(main):003> x = 12345678.12345678912
=> 12345678.12345679
irb(main):004> x.to_json
=> "1.234567812345679E7"

Versus (in Ruby 3.4.1):

irb(main):001> x = 1234567.1234567893
=> 1234567.1234567894
irb(main):002> x.to_json
=> "1234567.1234567894"
irb(main):003> x = 12345678.12345678912
=> 12345678.12345679
irb(main):004> x.to_json
=> "12345678.12345679"

In particular, this causes issues with JSON output containing timestamps in epoch+milliseconds output, such as what you would get from Time.now.to_f.

Lingua principale
Ruby
Stelle
782
Fork
383
Merge medio
1g 18h
PR unite (30g)
10

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/json

Tutte le issue di ruby/json

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.