Solidity-comparison-operators

提供:Dev Guides
移動先:案内検索

Solidity-比較演算子

次のコードは、Solidityで比較演算子を使用する方法を示しています。

pragma solidity ^0.5.0;

contract SolidityTest {
   uint storedData;
   constructor() public{
      storedData = 10;
   }
   function getResult() public view returns(string memory){
      uint a = 1;//local variable
      uint b = 2;
      uint result = a + b;
      return integerToString(result);
   }
   function integerToString(uint _i) internal pure
      returns (string memory _uintAsString) {

      if (_i == 0) {  //comparison operator
         return "0";
      }
      uint j = _i;
      uint len;

      while (j != 0) { //comparison operator
         len++;
         j/= 10;
      }
      bytes memory bstr = new bytes(len);
      uint k = len - 1;

      while (_i != 0) {
         bstr[k--] = byte(uint8(48 + _i % 10));
         _i/= 10;
      }
      return string(bstr);//access local variable
   }
}

link:/solidity/solidity_first_application [Solidity First Application]の章に記載されている手順を使用して、上記のプログラムを実行します。

出力

0: string: 3