Solidity string to uint
oraclize result以string格式返回,solidity没有uint(string)这样的强制转换功能,如果要解析其中的数字,可以用oraclize提供的parseInt方法:
pragma solidity ^0.4.21; import "github.com/oraclize/ethereum-api/oraclizeAPI.sol"; contract StringToUint is usingOraclize{ string price = "110.42"; string realStringPrice = "$10.33"; string badString = "abc"; uint public priceInt = parseInt(price,2); //11042 uint public priceIntger = parseInt(price); // 110 uint public realStringPriceInt = parseInt(realStringPrice,2); //1033 uint public realStringPriceInteger = parseInt(realStringPrice); //10 uint public badStringInt = parseInt(badString); //0 uint public badStringInteger = parseInt(badString,2); //0 }
1.001^365=1.44......life is a project
原创文章,转载请注明出处!