Skip to content

Float numbers in JSON stdout and http output plugin misformatted #6447

Closed as not planned

Description

@jennuineness

Bug Report

Describe the bug
Hi, I noticed certain float numbers such as 0.072 in a JSON data structure is being rewritten as 0.07199999999999999 when using the Format json option for the stdout and http output plugin.

I am sending out logs to a service that only accepts numbers with Decimal positions to be less than 16 digits. I am unable to find a way to preserve the number as-is when using the Format json option through the output plugins.

Any help with a fix/workaround is much appreciated!

To Reproduce

  • Rubular link if applicable:
  • Example log message if applicable:
{"test": 0.072}
  • Steps to reproduce the problem:

tail.conf

[SERVICE]
    Parsers_File parsers.conf
    Flush 0.1

[INPUT]
    Name            tail
    Path              /test.log
    Parser json

[OUTPUT]
    Name stdout
    Match *
    Format json
    json_date_key false

parsers.conf

[PARSER]
    Name   json
    Format json

test.log

{"test": 0.072}
  1. Setup environment with files listed above.
  2. Run following command in terminal where tail.conf is located: fluent-bit -c tail.conf
  3. Run the following command in a new terminal where test.log is located: echo '{"test": 0.072}' >> test.log

Expected behavior
Expect output to be [{"test":0.072}] instead of [{"test":0.07199999999999999}].

Your Environment

  • Version used: Fluent Bit v2.0.4
  • Configuration:
  • Environment name and version (e.g. Kubernetes? What version?):
  • Server type and version:
  • Operating System and version: MacOS Monterey v12.6
  • Filters and plugins: tail Input plugin, JSON parser plugin, stdout Output plugin, and HTTP Output plugin

Additional context

Possibly, allow an option to preserve the number types without being reformatted when parsing.

Activity

  1. nokute78 commented on Nov 26, 2022

    @nokute78
    Contributor

    Note: The issue is related %.16g.
    https://github.com/fluent/fluent-bit/blob/v2.0.6/src/flb_pack.c#L596

    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
      char *a = "0.072";
      double val = atof(a); 
    
      printf("%lf, %.16g\n", val, val);
      return 0;
    }
    $ ./a.out 
    0.072000, 0.07199999999999999
    

    Related PR:
    #1439
    #2592

  2. github-actions commented on Feb 24, 2023

    @github-actions
    Contributor

    This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the exempt-stale label.

  3. github-actions commented on Mar 1, 2023

    @github-actions
    Contributor

    This issue was closed because it has been stalled for 5 days with no activity.

  4. vitaly-sinev commented on Jul 21, 2026

    @vitaly-sinev
    Contributor

    This is still reproducible on current master — the Format json path in flb_pack.c still uses %.16g, so 0.072 serializes as 0.07199999999999999.

    I've opened #12129 with a fix: a shared flb_pack_double_to_str() helper that uses the already-vendored yyjson dtoa to emit the shortest decimal string that round-trips back to the same double (so 0.072 → "0.072"), while still guaranteeing round-trip precision (unlike a plain %.15g). Non-finite values keep their previous formatting.

    Could a maintainer please reopen this issue? Thanks to @nokute78 for pinpointing the %.16g root cause.

  5. added 6 commits that reference this issue on Jul 21, 2026
    6ae4e82
    d04dd0a
    326a651
    5a99f51
    ead2ef0
    4f33276
  6. added 4 commits that reference this issue on Jul 31, 2026
    3ace0b3
    80b8a4a
    c13eae6
    fc3f601
  7. added 2 commits that reference this issue on Sep 20, 2026
    aab0fd1
    3429924
  8. added 2 commits that reference this issue on Oct 17, 2026
    fd24285
    9b93931
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions