# Ratio

Jakob Jenkov |

The term *ratio* means the ratio between two numbers, also sometimes referred to as the proportion between two
numbers. The ratio is calculated by dividing one number
by the other. Thus, the ratio of A and B is A divided by B. For instance, the ratio between 5 and 10 is
5 divided by 10, which is 0.5 .

Ratios are usually used to express the size of one number relative to another. For instance, how many of the sold cars were green cars? In other words, the ratio of green cars to sold cars in total. To calculate that ratio you divide the number of sold green cars by the total number of sold cars.

In other tutorials in this mathematical analysis tutorial I will be using the following notation for ratio:

ratio(a, b)

This is a functional notation where `ratio`

is a function that divides one number by another,
and `a`

is the number to by divided by `b`

. For instance, the ratio between 5 and 10
would be written like this:

ratio(5, 10)

The ratio between the number of sold green cars and the number of total sold cars could be expressed like this:

ratio(count(soldCars, "color", "green"), count(soldCars))

Notice how this notation uses the count notation internally, because we use the count function to count the number of sold green cars and the total number of sold cars.

Tweet | |

Jakob Jenkov |