provable-things / ethereum-api

Provable API for Ethereum smart contracts
https://docs.provable.xyz/#ethereum
MIT License
801 stars 427 forks source link

Convert Uint to String #118

Open aurelienchev opened 1 year ago

aurelienchev commented 1 year ago

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); }