zoukankan      html  css  js  c++  java
  • 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 
    }
  • 相关阅读:
    CF235D
    模拟赛 circle 题解
    平面图总结
    kd 树总结
    思维题
    luogu P1600 天天爱跑步
    UOJ #42. 【清华集训2014】Sum
    FZOJ 4344 连通性
    平衡树
    计蒜客 T3225 Darko 的生成树
  • 原文地址:https://www.cnblogs.com/huahuayu/p/8668844.html
Copyright © 2011-2022 走看看