I got a problem with rounding 135.345 to two decimals: it becomes 135.34 instead of 135.35. I traced it down to this code in number_formatter.cpp:
else if (p.type == format_placeholders::placeholders_type::fractional_part)
{
auto fractional_part = number - integer_part;
result = std::fabs(fractional_part) < std::numeric_limits<double>::min()
? std::string(".")
: serialiser_.serialise_short(fractional_part).substr(1);
The problem is with the fractional_part which is 135.345 - 135 = 0.344999999999, which then gets rounded to 0.34 which is correct for that number, but not for the original one.
I'd change it this way:
if (std::fabs(fractional_part) < std::numeric_limits<double>::min())
{
result = std::string(".");
}
else
{
result = serialiser_.serialise_short(fractional_part);
result = result.substr(result.find('.'));
}
so the whole number is formatted and then the integer part is removed.
I got a problem with rounding
135.345
to two decimals: it becomes135.34
instead of135.35
. I traced it down to this code innumber_formatter.cpp
:The problem is with the
fractional_part
which is135.345 - 135 = 0.344999999999
, which then gets rounded to0.34
which is correct for that number, but not for the original one.I'd change it this way:
so the whole number is formatted and then the integer part is removed.