Merge pull request #11804 from ethereum/fixedPointTypes

[isoltest] Leading zero for fixed point types.
This commit is contained in:
chriseth 2021-08-16 22:17:48 +02:00 committed by GitHub
commit b62bb0a0b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -232,8 +232,8 @@ std::string BytesUtils::formatFixedPoint(bytes const& _bytes, bool _signed, size
if (_fractionalDigits > 0)
{
size_t numDigits = decimal.length() - (negative ? 1 : 0);
if (_fractionalDigits > numDigits)
decimal.insert(negative ? 1 : 0, string(_fractionalDigits - numDigits, '0'));
if (_fractionalDigits >= numDigits)
decimal.insert(negative ? 1 : 0, string(_fractionalDigits + 1 - numDigits, '0'));
decimal.insert(decimal.length() - _fractionalDigits, ".");
}
return decimal;

View File

@ -35,11 +35,11 @@ BOOST_AUTO_TEST_CASE(format_fixed)
{
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{0}), true, 2),
".00"
"0.00"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{1}), true, 2),
".01"
"0.01"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{123}), true, 2),
@ -47,11 +47,11 @@ BOOST_AUTO_TEST_CASE(format_fixed)
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-1}), true, 2),
"-.01"
"-0.01"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-12}), true, 2),
"-.12"
"-0.12"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-123}), true, 2),