Output formatting differences between jRuby 10.0.0.1 and Ruby 3.4 when converting Float to JSON.
@headius đang làm issue này rồi.
Từ ngày 25/8/2025.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Ruby
- Star
- 782
- Fork
- 383
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 10
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ruby/json
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Can `ResumableParser` return whether the last `partial_value` container is completed or not? Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
jruby
-
new feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
simp/pupmod-simp-simp#395 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
simp/pupmod-simp-rsyslog#219 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
simp/pupmod-simp-pupmod#256 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
simp/pupmod-simp-sudo#150 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100