Skip to content

Convert Uint to String #118

@aurelienchev

Description

@aurelienchev

on version 0.8, the function for conversion uint -> string is not working.

update potential:
function uint2str(uint _i) internal pure returns (string memory str) {
if (_i == 0){
return "0";
}
uint256 j = _i;
uint256 length;
while (j != 0){
length++;
j /= 10;
}
bytes memory bstr = new bytes(length);
uint256 k = length;
j = _i;
while (j != 0)
{
bstr[--k] = bytes1(uint8(48 + j % 10));
j /= 10;
}
str = string(bstr);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions