# How ensure a whole number deposit (Integer)

**URL:** <https://forum.soliditylang.org/t/how-ensure-a-whole-number-deposit-integer/1614>\
**Category:** Code Wizards\
**Created:** [April 11, 2023, 11:04am UTC](https://forum.soliditylang.org/t/how-ensure-a-whole-number-deposit-integer/1614 "2023-04-11T11:04:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![esodot](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/esodot/32/929_2.png) [@esodot](https://forum.soliditylang.org/u/esodot)\
**Post date:** [April 11, 2023, 11:04am UTC](https://forum.soliditylang.org/t/how-ensure-a-whole-number-deposit-integer/1614/1 "2023-04-11T11:04:01Z")

</div>

Hello Community,  
please bear with me this might be a dump question but i can’t wrap my head around that:

User should be able to deposit an uint amount between 1 and 10 (integer 1,2,3,4,5,6,7,8,9 or 10) to take part in a raffle. I have a function taking users amount:

> function takePartInRaffle(uint \_amount) external activeContract {  
> require(\_amount \> 0, “amount is 0”);  
> require(\_amount \<= maxRaffleVouchers, “max vouchers limit”);  
> …  
> …

as the user is able to deposit any uint like 1.5 ETH or 1.22 ETH i am stuck and don’t know how to write a require precondition here. Also not sure if i am completely on a wrong path with my idea to prevent / force the user to deposit a whole / integer number.

Would be awesome to get some answers on that.

Kind regards  
esodot

---

<div class="post-metadata">

**Author:** ![tiFFanyAhn](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/tiffanyahn/32/926_2.png) [@tiFFanyAhn](https://forum.soliditylang.org/u/tiFFanyAhn)\
**Post date:** [April 11, 2023, 9:53pm UTC](https://forum.soliditylang.org/t/how-ensure-a-whole-number-deposit-integer/1614/2 "2023-04-11T21:53:02Z")

</div>

You don’t need to worry about that.  
That amount has decimals. For example, Eth has 18 decimals.  
So if user bet 1.22ETH, \_amount will be 1,220,000,000,000,000,000.  
If you want to make people to bet only unit amount(1ETH, 2ETH…), you can use modulo operator.  
But I dont think it’s needed.

---

<div class="post-metadata">

**Author:** ![Tudmotu](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/tudmotu/32/818_2.png) [@Tudmotu](https://forum.soliditylang.org/u/Tudmotu)\
**Post date:** [April 13, 2023, 10:42am UTC](https://forum.soliditylang.org/t/how-ensure-a-whole-number-deposit-integer/1614/3 "2023-04-13T10:42:39Z")

</div>

I believe you are missing some info on two subjects here:

1. Understanding how units in Ethereum work
2. Understanding how “money” is transferred in a smart contract

**Units**  
On the blockchain, there are no fractions. Everything is an integer, meaning a whole number, with no decimal point.

How do we represent 1.1 ETH then?  
The actual unit-of-account on Ethereum is called “Wei”, and every ETH is actually 10^18 Wei, so:  
1 ETH == 1,000,000,000,000,000,000 Wei

If you want to represent 1.1 ETH, you denominate it in Wei:  
1.1 ETH == 1,100,000,000,000,000,000 Wei

Solidity provides several convenience shorthand units, for example `ether`.  
Instead of writing `uint amount = 1000000000000000000`, you can write `uint amount = 1 ether`.

Check out [the docs](https://docs.soliditylang.org/en/v0.8.19/units-and-global-variables.html) to see what shorthand units Solidity provides.

Hope this helps with understanding units.

**How to transfer money**  
If you want to be able to accept money inside a smart contract function, you need to mark it `payable`:

```auto
function takePartInRaffle(uint _amount) external activeContract payable {
...
}

```

And to access the transferred amount, you don’t use a function parameter, you use a special variable: `msg.value`. This variable contains the amount of Wei transferred along with the transaction.  
So if you want, for example, to require someone to send at least 1 ETH, you would use:

```auto
require(msg.value > 1000000000000000000);

```

Or, using the Solidity units:

```auto
require(msg.value > 1 ether);

```

These two are the same.

Check out [this StackExchange answer](https://ethereum.stackexchange.com/questions/43362/what-is-msg-value) for more info.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![esodot](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/esodot/32/929_2.png) [@esodot](https://forum.soliditylang.org/u/esodot)\
**Post date:** [April 13, 2023, 5:12pm UTC](https://forum.soliditylang.org/t/how-ensure-a-whole-number-deposit-integer/1614/4 "2023-04-13T17:12:30Z")

</div>

Thank you very much for the great explanation. I really was not aware how the decimals and fractions are handled. Make sense now! 👍
