Menu
Coddy logo textTech

Integer Division

Part of the Fundamentals section of Coddy's Solidity journey. Lesson 13 of 53.

Use / to divide integer values. When both operands are integer variables, the result is an integer: any fractional part is discarded toward zero. For nonnegative values this counts complete groups. The divisor must not be zero.

The statements in this excerpt run inside the provided main function.

uint256 items = 23;
uint256 capacity = 6;
console.log(items / capacity);

Three full groups of six fit into twenty-three. Integer division reports three, not a decimal and not a rounded-up four. Here both operands are typed variables, which avoids confusing integer division with compile-time rational literal expressions.

Integer division discards the fractional part toward zero.

challenge icon

Challenge

Easy

There are pieces pieces and each complete kit uses perKit pieces. Print how many complete kits can be made. perKit is greater than zero.

The tests pass arguments to main in this order: uint256 pieces, uint256 perKit. Each test starts with fresh contract state.

Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.

Try it yourself

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
    function main(uint256 pieces, uint256 perKit) external view {
        // Write your solution here.
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Solidity playground