Skip to content

document that std::fmt uses ROUND_HALF_EVEN #112742

Closed
@Krappa322

Description

@Krappa322

I tried this code:

    println!("{:.0}", 10.5f64);

I expected to see this happen: It prints 11

Instead, this happened: It prints 10

As far as I am able to find 10.5 has a perfect (lossless) representation in f64-space so it does not seem to be because of floating point error to me.

If I put in 9.5 instead it does work as expected (it prints 10), which is weird because that also has a perfect representation as f64. Is it applying a round_ties_even() kind of logic? If it is then I would expect this to be documented e.g. under https://doc.rust-lang.org/std/fmt/#precision

Meta

I've been using rust playground, rust version 1.70.0

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-floating-pointArea: Floating point numbers and arithmeticT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions