[isoltest] Add support for fixed point types.

This commit is contained in:
Alexander Arlt 2021-07-27 09:32:34 -05:00 committed by chriseth
parent c0a9578979
commit 866617b353
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),