Add Strings.toString for signed integers (#3773)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Gbolahan <89295500+GbolahanAnon@users.noreply.github.com> Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -9,6 +9,10 @@ contract StringsMock {
|
||||
return Strings.toString(value);
|
||||
}
|
||||
|
||||
function toString(int256 value) public pure returns (string memory) {
|
||||
return Strings.toString(value);
|
||||
}
|
||||
|
||||
function toHexString(uint256 value) public pure returns (string memory) {
|
||||
return Strings.toHexString(value);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./math/Math.sol";
|
||||
import "./math/SignedMath.sol";
|
||||
|
||||
/**
|
||||
* @dev String operations.
|
||||
@ -37,6 +38,13 @@ library Strings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Converts a `int256` to its ASCII `string` decimal representation.
|
||||
*/
|
||||
function toString(int256 value) internal pure returns (string memory) {
|
||||
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user