mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-08 03:43:13 +00:00
Fix group_digits for negative integers (#3901)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
parent
365c3fbd25
commit
6c7cc6a06f
@ -4130,9 +4130,10 @@ template <typename T> struct formatter<group_digits_view<T>> : formatter<T> {
|
||||
specs.width_ref, ctx);
|
||||
detail::handle_dynamic_spec<detail::precision_checker>(
|
||||
specs.precision, specs.precision_ref, ctx);
|
||||
return detail::write_int(ctx.out(),
|
||||
static_cast<detail::uint64_or_128_t<T>>(t.value),
|
||||
0, specs, detail::digit_grouping<char>("\3", ","));
|
||||
auto arg = detail::make_write_int_arg(t.value, specs.sign);
|
||||
return detail::write_int(
|
||||
ctx.out(), static_cast<detail::uint64_or_128_t<T>>(arg.abs_value),
|
||||
arg.prefix, specs, detail::digit_grouping<char>("\3", ","));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1837,6 +1837,9 @@ TEST(format_test, bytes) {
|
||||
TEST(format_test, group_digits_view) {
|
||||
EXPECT_EQ(fmt::format("{}", fmt::group_digits(10000000)), "10,000,000");
|
||||
EXPECT_EQ(fmt::format("{:8}", fmt::group_digits(1000)), " 1,000");
|
||||
EXPECT_EQ(fmt::format("{}", fmt::group_digits(-10000000)), "-10,000,000");
|
||||
EXPECT_EQ(fmt::format("{:8}", fmt::group_digits(-1000)), " -1,000");
|
||||
EXPECT_EQ(fmt::format("{:8}", fmt::group_digits(-100)), " -100");
|
||||
}
|
||||
|
||||
#ifdef __cpp_generic_lambdas
|
||||
|
Loading…
Reference in New Issue
Block a user