Skip to content

Commit 437fec2

Browse files
committed
Rule of rounding applies to both sides of the decimal point
1 parent b1c017d commit 437fec2

File tree

1 file changed

+2
-1
lines changed
  • include/boost/charconv/detail/dragonbox

1 file changed

+2
-1
lines changed

include/boost/charconv/detail/dragonbox/floff.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4018,9 +4018,10 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, int precision,
40184018
++decimal_dot_pos;
40194019
}
40204020
}
4021-
else if (decimal_exponent_normalized == 0)
4021+
else if (decimal_exponent_normalized == 0 || remaining_digits == 1)
40224022
{
40234023
// For the case 0.99...9 -> 1.00...0, the rounded digit is one before the first digit written.
4024+
// This same case applies for 0.099 -> 0.10 in the precision = 2 instance
40244025
// Note: decimal_exponent_normalized was negative before the increment (++decimal_exponent_normalized),
40254026
// so we already have printed "00" onto the buffer.
40264027
// Hence, --digit_starting_pos doesn't go more than the starting position of the buffer.

0 commit comments

Comments
 (0)