A fraction is an expression that expresses a number less than 1.

Decimal Fractions

All fractions in programming are decimal fractions, which makes working with fractions easy.

Decimal fractions are represented as a decimal number. For example $\frac{1}{2}$ is 0.5 as a decimal fraction.

Such fractions require using floats as the data type.


fraction# = 0.5
Print fraction#

Division can be used to create a decimal fraction. Float() is required to ensure that the division returns a decimal number. Otherwise, it returns an integer.

fraction# = Float(1)/2
Print fraction#

Fraction Parts

\begin{align} \frac{numerator}{denominator} \end{align}

Fractions divide a whole number into equal parts, called the denominator. If you wanted to divide up your spoils of conquest between 5 people, you would divide it into equal shares of $5$ (if everyone is fair and weaponry is not in the equation). 5, in this case would be the denominator, as we have divided the whole into five equal shares.

How much of the whole is determined by the numerator. Since we are dividing it equally, the numerator would be 1, as each person gets $\frac{1}{5}$ of the conquest. If one of the members were to steal the share of another, he would have $\frac{2}{5}$ of the conquest, making the numerator $2$, as he has $2$ shares of the $5$ equal parts.

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.