【單位】

如同前一個章節在整數時的內容,我們沒辦法使用小數來表達一個值,所以在 Solidity 裡面有許多單位可供使用。

Unit
wei value
wei
ether value

wei

1 wei

1

10^-18 ETH

kwei

10^3 wei

1,000

10^-15 ETH

mwei

10^6 wei

1,000,000

10^-12 ETH

gweiv

10^9 wei

1,000,000,000

10^-9 ETH

microether

10^12 wei

1,000,000,000,000

10^-6 ETH

milliether

10^15 wei

1,000,000,000,000,000

10^-3 ETH

ether

10^18 wei

1,000,000,000,000,000,000

1 ETH

pragma solidity ^0.8.11;

contract MyUnits {
    // 1 wei == 1;
    // 1 gwei == 1e9;
    // 1 ether == 1e18;
    uint256 public costOfNFT = 0.0000000000005 ether;
}

Last updated

Was this helpful?