Trusted answers to developer questions

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The ** div() function** in Ruby returns the result of the integer division of two numbers, e.g., dividend/divisor.

Figure 1 shows the visual representation of the `div()`

function.

```
dividend.div(divisor)
```

This function requires a divisor as a parameter.

If the divisor is

`zero`

, then this function throws`ZeroDivisionError`

.

This function does the `integer division`

of the two numbers and returns its result, e.g., dividend/divisor.

If the result is floating-point, then this function

rounds downor takes the`floor`

of the result and gives the integer value.

The following example shows how to use the `div()`

function in Ruby.

#both positive numbersprint "(15).div(4) : ",(15).div(4), "\n"#negative dividendprint "(-15).div(6): ",(-15).div(6), "\n"#zero dividendprint "(0).div(12): ",(0).div(12), "\n"#fractional numbers and both numbers negativeprint "(-15.6).div(-6.7): ",(-15.6).div(-6.7), "\n"

RELATED TAGS

ruby

math

division

integer

communitycreator

CONTRIBUTOR

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses