Skip to content

Bug: Shortest floating point representation: redundant trailing 0's #1873

@AlbertoEAF

Description

@AlbertoEAF

Hello,

I am using fmt::format to print numbers in several formats. One of them is floating point in shortest representation, but when numbers come out in scientific notation I sometimes have trailing 0's.

Original call
snprintf(buffer, buf_len, "%g", value)

New call
fmt::format("{:g}", value)

Up to now, writing many floating point numbers, all the mismatches I have are with the scientific notation and trailing zeros. This are some kinds of mismatches I'm having (red = original code output, green = new code output):
image

image

I know this seems "irrelevant" but it's enough to disturb LightGBM as is currently implemented.

Any suggestions? Am I calling something wrong? Is it supposed to happen?
(I really need this working this week, so I can for the time being do a pass over the output buffer and trim trailing 0's but let's say that's neither "fast" nor "the correct way").

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions