Skip to content

bug: float values like 1.0 output as integers (1) — type fidelity loss breaks downstream schema #444

Closed

Description

@strawgate

Summary

JSON float values that happen to be whole numbers (e.g., 1.0, 2.0, 100.0) are output as integers (1, 2, 100). This changes the JSON type from number-with-decimal to integer, which can break downstream schema inference and type mappings.

Root Cause

The scanner correctly identifies 1.0 as a float (the . triggers is_float = true in scanner.rs line ~194). The value is stored as f64 via append_float_by_idx. However, write_row_json uses Rust's format!("{}", v) to render float values, and Rust's f64::Display drops trailing zeros:

// crates/logfwd-output/src/lib.rs line ~188
"float" => {
    let v = arr.value(row);
    let _ = Write::write_fmt(out, format_args!("{}", v));
    // 1.0f64 displays as "1", not "1.0"
}

Reproduction

printf '{"temp":1.0,"pressure":2.0,"ratio":1.5}\n' > /tmp/float.log
input:
  type: file
  path: /tmp/float.log
  format: json
output:
  type: stdout

Actual output:

{"temp":1,"pressure":2,"ratio":1.5}

Expected output:

{"temp":1.0,"pressure":2.0,"ratio":1.5}

Impact

  • Elasticsearch: infers temp as long instead of double, then rejects 1.5 in a later batch with a mapping conflict
  • ClickHouse: creates Int64 column instead of Float64
  • JSON schema validation: downstream validators may reject changed types
  • Round-trip fidelity: input → logfwd → output changes the data representation

Fix

Use a float-specific formatter that preserves at least one decimal place:

"float" => {
    let v = arr.value(row);
    if v.fract() == 0.0 && v.is_finite() {
        let _ = write!(out, "{}.0", v);  // Preserve float type
    } else {
        let _ = write!(out, "{}", v);
    }
}

Or use ryu crate for fast, correct float-to-string conversion that preserves the decimal.

Activity

  1. github-actions commented on Mar 31, 2026

    @github-actions
    Contributor

    No clear duplicate found for this issue.

    3 related issues

    Note

    🔒 Integrity filtering filtered 2 items

    Integrity filtering activated and filtered the following items during workflow execution.
    This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.


    What is this? | From workflow: AI: Duplicate Issue Detector

    Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

  2. added 2 commits that reference this issue on Apr 1, 2026
    8a5b359
    035b96f
  3. strawgate commented on Apr 2, 2026

    @strawgate
    OwnerAuthor

    Closed — write_json_value dispatches on DataType::Float64 (PR #568).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions