solidity系列教程<六>单位

以太单位

一个整数的后面可以跟一个单位,ether,finney,szabo或者wei:

他们的单位换算如下:

  • 1 ether = 1000 finney
  • 1 ether = 1000000 szabo
  • 1 ether = 10 ** 18 wei
pragma solidity ^0.4.14;

contract C {
    uint a = 1 ether;
    uint b = 10 ** 18 wei;
    uint c = 1000 finney;
    uint d = 1000000 szabo;
    function isTrueAEquleToB() view public returns (bool) {
        return a == b;
    } 
    function isTrueAEquleToC() view public returns (bool) {
        return a == c;
    }
    function isTrueAEquleToD() view public returns (bool) {
        return a == d;
    }
}

时间单位

时间的单位有seconds, minutes, hours, days, weeks 和 years。换算如下:

  • 1 == 1 seconds
  • 1 minutes == 60 seconds
  • 1 hours == 60 minutes
  • 1 days == 24 hours
  • 1 weeks == 7 days
  • 1 years == 365 days
pragma solidity ^0.4.4;

contract C {
    
    // 1 == 1 seconds
    // 1 minutes == 60 seconds
    // 1 hours == 60 minutes
    // 1 days == 24 hours
    // 1 weeks == 7 days
    // 1 years == 365 days
    function test1() pure public returns (bool) {
        return 1 == 1 seconds;
    }
    function test2() pure public returns (bool) {
        return 1 minutes == 60 seconds;
    }
    function test3() pure public returns (bool) {
        return 1 hours == 60 minutes;
    }
    function test4() pure public returns (bool) {
        return 1 days == 24 hours;
    }
    function test5() pure public returns (bool) {
        return 1 weeks == 7 days;
    }
    function test6() pure public returns (bool) {
        return 1 years == 365 days;
    }
}

你可能感兴趣的:(solidity系列教程<六>单位)