diff --git a/AK/Format.cpp b/AK/Format.cpp index 757b3f5406..8ea0e73391 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -396,7 +396,7 @@ ErrorOr FormatBuilder::put_fixed_point( u64 scale = pow(10, precision); auto fraction = (scale * fraction_value) / fraction_one; // TODO: overflows - if (is_negative) + if (is_negative && fraction != 0) fraction = scale - fraction; size_t leading_zeroes = 0; diff --git a/Tests/AK/TestFixedPoint.cpp b/Tests/AK/TestFixedPoint.cpp index 5622f56ec4..cf7806603b 100644 --- a/Tests/AK/TestFixedPoint.cpp +++ b/Tests/AK/TestFixedPoint.cpp @@ -178,4 +178,8 @@ TEST_CASE(formatter) EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.1)), "-0.100007"sv); EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.02)), "-0.020005"sv); EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.0000000005)), "0"sv); + + EXPECT_EQ(DeprecatedString::formatted("{}", Type(-1)), "-1"sv); + EXPECT_EQ(DeprecatedString::formatted("{}", Type(-2)), "-2"sv); + EXPECT_EQ(DeprecatedString::formatted("{}", Type(-3)), "-3"sv); }