google / google/double-conversion

Feature request: rounding half to even

Open
#251 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.2k
Forks
308
Avg merge
2d 9h
Merged PRs (30d)
12

Description

Hi,

This has already been discussed in #72 , but I'd like to resubmit it as a feature request.

Double to string conversion currently rounds half away from zero: 0.25 (precise) printed with 1 digit of precision yields "0.3".
This is documented here https://github.com/google/double-conversion/blob/master/double-conversion/double-to-string.h#L404 (search for "halfway cases").

However rounding away from zero is not what most C++ code does by default: `printf`, `std::print`, `std::to_chars` etc. all round half to even. (One would also argue, this is what most other programming languages do.) They would print "0.2" in the above example, not "0.3".

It would be nice to have a way to pass a flag or similar in order to request this rounding form from `DoubleToStringConverter`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.