pragma solidity ^0.4.24; contract A { function test() external pure returns (string) { uint256 temp = 345342342342345; string memory s = string(abi.encodePacked("a", " ", "concatenated", " ", "string", " ", uint2str(temp))); //string memory s = uint2str(temp); return s; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint length; while (j != 0){ length++; j /= 10; } bytes memory bstr = new bytes(length); uint k = length - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } function uint2hexstr(uint i) internal pure returns (string) { if (i == 0) return "0"; uint j = i; uint length; while (j != 0) { length++; j = j >> 4; } uint mask = 15; bytes memory bstr = new bytes(length); uint k = length - 1; while (i != 0){ uint curr = (i & mask); bstr[k--] = curr > 9 ? byte(55 + curr ) : byte(48 + curr); // 55 = 65 - 10 i = i >> 4; } return string(bstr); } function uintToString(uint v) private pure returns (string str) { uint maxlength = 100; bytes memory reversed = new bytes(maxlength); uint i = 0; while (v != 0) { uint remainder = v % 10; v = v / 10; reversed[i++] = byte(48 + remainder); } bytes memory s = new bytes(i + 1); for (uint j = 0; j <= i; j++) { s[j] = reversed[i - j]; } str = string(s); } function uintToBytes(uint v) private pure returns (bytes32 ret) { if (v == 0) { ret = '0'; } else { while (v > 0) { ret = bytes32(uint(ret) / (2 ** 8)); ret |= bytes32(((v % 10) + 48) * 2 ** (8 * 31)); v /= 10; } } return ret; } function bytes32ToString (bytes32 data) private pure returns (string) { bytes memory bytesString = new bytes(32); for (uint j=0; j<32; j++) { byte char = byte(bytes32(uint(data) * 2 ** (8 * j))); if (char != 0) { bytesString[j] = char; } } return string(bytesString); } }
0.4.18