# Fixed Point Numbers

Using a fixed point is one method of representing real numbers.

Say we have four boxes, each of which can accept one decimal digit. Using the four boxes we can represent numbers in the range of zero to 9999.

But what if we wanted to represent fractional numbers using only four digits? What we could do is simply insert a decimal point somewhere between the four boxes like in these examples:

In the first example we can represent whole numbers in the range 0 - 99 and after the decimal point we can have two decimal places. In the second example we can represent whole numbers in the range 0 - 999 but we only get one decimal place. In the third example we can only represent whole numbers in the range 0 - 9 but we can have three decimal places.

Calculations work in exactly the same way no matter where we put the decimal point, as long as we ensure we keep the decimal point in the same place for all of the numbers we are working with. For example say we do this calculation with integers only:

```
0370 +
0099
----
0469
----
```

If we split up the four digits and have 2 whole numbers and 2 decimal places, the calculation is exactly the same with the exact same digits in the same positions resulting:

```
03.70 +
00.99
-----
04.69
-----
```

Or if we have 1 whole number and 3 decimal places, still the same digits result from the calculation:

```
0.370 +
0.099
-----
0.469
-----
```

The position in which we decide to put the imaginary decimal point makes no difference at all as to how the calculation is done or what digits result from the calculation.

One limitation is the number of decimal places has to stay the same for all the numbers in the calculation. We can’t decide to mix and match numbers with differing numbers of digits either side of the decimal point otherwise the calculation goes wrong. For example we can’t do this:

```
1.001 +
100.1
-----
20.02 <-- Wrong Answer
-----
```

You have to pick a fixed number of decimal places and then stick to it. This is **fixed point** arithmetic.

One way in which fixed point arithmetic is commonly used is when doing calculations with **money**. In many currencies, we have two units, a whole unit and a unit that represents hundreths, that is we have pounds and pence or we have dollars and cents. Calculations with money are consequently routinely performed to two decimal places only. That is, there is a fixed point.

When doing calculations with money we can do the calculation as integers with an imaginary two decimal places. Another way of thinking about it is when we do the calculation all the money is converted to pence or cents. We do the calculation as the hundreths unit and then simply insert the decimal point when we print the number on the screen and it’s now in whole units and hundreths again.

The advantage of fixed point numbers is calculations work in exactly the same way for fractional numbers as they do for integers. This means in a CPU the integer arithmetic circuits can be recycled to also deal with fractional numbers, which takes up less space on the chip and means it can be cheaper. Using fixed point numbers can also often be faster than other methods of dealing with fractional numbers.

A problem with fixed point numbers is it limits the range and precision of numbers we can work with. To help overcome these problems, we need a floating point number representation system, which offer a great deal more flexibility but is more complex.