You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
916 B
34 lines
916 B
5 years ago
|
pragma solidity ^0.6.0;
|
||
6 years ago
|
|
||
|
/**
|
||
|
* @title Strings
|
||
|
* @dev String operations.
|
||
|
*/
|
||
|
library Strings {
|
||
|
/**
|
||
5 years ago
|
* @dev Converts a `uint256` to its ASCII `string` representation.
|
||
6 years ago
|
*/
|
||
|
function fromUint256(uint256 value) internal pure returns (string memory) {
|
||
5 years ago
|
// Inspired by OraclizeAPI's implementation - MIT licence
|
||
|
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
|
||
|
|
||
6 years ago
|
if (value == 0) {
|
||
|
return "0";
|
||
|
}
|
||
|
uint256 temp = value;
|
||
|
uint256 digits;
|
||
|
while (temp != 0) {
|
||
|
digits++;
|
||
|
temp /= 10;
|
||
|
}
|
||
|
bytes memory buffer = new bytes(digits);
|
||
|
uint256 index = digits - 1;
|
||
|
temp = value;
|
||
|
while (temp != 0) {
|
||
|
buffer[index--] = byte(uint8(48 + temp % 10));
|
||
|
temp /= 10;
|
||
|
}
|
||
|
return string(buffer);
|
||
|
}
|
||
|
}
|