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 
}

 

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
猜你喜欢
  • 2021-09-26
  • 2021-08-18
  • 2022-12-23
  • 2021-09-22
  • 2021-05-16
  • 2022-02-17
  • 2021-07-15
相关资源
相似解决方案