File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -94,12 +94,21 @@ bytes BytesUtils::convertNumber(string const& _literal)
94
94
bytes BytesUtils::convertFixedPoint (string const & _literal, size_t & o_fractionalDigits)
95
95
{
96
96
size_t dotPos = _literal.find (' .' );
97
- string valueInteger = _literal.substr (0 , dotPos);
98
- string valueFraction = _literal.substr (dotPos + 1 );
99
- o_fractionalDigits = valueFraction.length ();
97
+ o_fractionalDigits = dotPos < _literal.size () ? _literal.size () - dotPos : 0 ;
98
+ bool negative = !_literal.empty () && _literal.at (0 ) == ' -' ;
99
+ // remove decimal point
100
+ string valueInteger = _literal.substr (0 , dotPos) + _literal.substr (dotPos + 1 );
101
+ // erase leading zeros to avoid parsing as octal.
102
+ while (!valueInteger.empty () && (valueInteger.at (0 ) == ' 0' || valueInteger.at (0 ) == ' -' ))
103
+ valueInteger.erase (valueInteger.begin ());
104
+ if (valueInteger.empty ())
105
+ valueInteger = " 0" ;
100
106
try
101
107
{
102
- return util::toBigEndian (u256 (valueInteger + valueFraction));
108
+ u256 value (valueInteger);
109
+ if (negative)
110
+ value = s2u (-u2s (value));
111
+ return util::toBigEndian (value);
103
112
}
104
113
catch (std::exception const &)
105
114
{
You can’t perform that action at this time.
0 commit comments