# Formatting Big Numbers: The “aa” Notation

If you are dealing with big numbers in your game, you might have encountered the issue of properly formatting them. Small numbers such as 1.000, 10.000 or even 100.000 are OK, but as you go larger, you’ll run out of space quickly. I mean, how can you fit **1.000.000.000.000.000.000** in a button?

But let’s say, you found a way. Let’s say you were able to put **1.000.000.000.000.000.000** in a button properly and it looks good (I can’t imagine how, but for the sake of the argument let’s assume it is possible). However, you still have the UX problem of clarity. No one will be able to see this number and say “oh my gosh, I have one quintillion cookies!”. I am a mathematician and even I can’t read it without counting zeros first.

There are two solutions to this problem and they both have pros and cons:

### Scientific notation

Mostly used by scientists and engineers, this notation is formatted as follows:

m x 10^{n} |

Where **m** is a real number called *coefficient*, and **n** is an integer called *mantissa*. In order to make this more concrete, let’s have a look at some examples:

Number | Scientific notation |

1 | 1 |

1.000 | 1×10^{3} |

5.000 | 5×10^{3} |

1.250.000 | 1,25×10^{6} |

1.254.678 | 1,254678×10^{6} |

1.500.000.000 | 1,5×10^{9} |

The good thing about this notation is that you can format any number. Moreover, by using only 2 (or as much as you want) digits after the decimal point, you can make your numbers fit in a limited amount of space.

The problem is that this notation is used by scientists and engineers (as I mentioned earlier), and it will not make any sense to most people. Even if it does, superscripts (I mean ^{this}) would look really tiny on mobile screens and would cause minor UX problems.

### Single letter notation

There is no science backing up this notation, it’s something purely linguistic: single letter after the number. This is the notation you use in your daily life.

Number | Single letter notation |

1 | 1 |

1.000 | 1k |

5.000 | 5k |

1.250.000 | 1,25m |

1.254.678 | 1,254678m |

1.500.000.000 | 1,5b |

Since it’s already used by everyone, this notation has the advantage of being accessible. Almost everyone can tell 1.25m means *one million two hundred fifty thousand*. However, not many people would know that **q** in **1.25q** stands for *quadrillion* and it becomes more of an issue as you go larger. See for yourself: quintillion, sextillion, septillion, octillion, nonillion. Do you see anything familiar? Probably no, because these units are not used in daily life unless you are a scientist or a mathematician. We need something more intuitive.

### The “aa” notation

A better solution is the combination of the two: single letter notation up until (but not including) quadrillion and a two letter representation of scientific notation after trillion. It may sound confusing, but you’ll agree that it’s actually rather clear when you see it in action:

Number | Written | Scientific | Single letter | “aa” |

1 | one | 1 | 1 | 1 |

1.000 | one thousand | 1×10^{3} | 1k | 1k |

1.000.000 | one million | 1×10^{6} | 1m | 1m |

1.000.000.000 | one billion | 1×10^{9} | 1b | 1b |

1.000.000.000.000 | one trillion | 1×10^{12} | 1t | 1t |

1.000.000.000.000.000 | one quadrillion | 1×10^{15} | 1q | 1aa |

1.000.000.000.000.000.000 | one quintillion | 1×10^{18} | 1? | 1ab |

So, one quadrillion (10^{15}) will be represented with **aa**. For every power of 1000 we’ll move the second letter up, so one quintillion (10^{18}) will be **ab**, one sextillion will be **ac**, and so on. After **az**, we’ll move to **ba**, **bb**, **bc** etc. This algorithm provides an incremental representation of big numbers and it does not require any scientific or mathematical knowledge. The algorithm for this notation is rather simple and it’s really easy to implement in any programming language.

First we need to represent the number in a slightly modified scientific notation. Since we change the unit for every power of 1000 we’ll convert our number to this: m x 1000^{n }. In order to find m and n, all we have to do is revert the formula and apply it:

1 2 | n = (int) log(value, 1000); m = value / pow(1000, n); |

If n is less than 5 (i.e the number is less than 1×10^{15}), we will use the single letter notation (K, M, B, or T). If it is greater than or equal to 5, we’ll convert this number to “aa” notation. So 5 (10^{15}) will be **aa**, 6 (10^{18}) will be **ab**, 7 (10^{21}) will be **ac** and so on. Since there are 26 letters in English language, converting n to a two letter representation would require one modulo and one division operations:

1 2 3 | secondUnit = n % 26; firstUnit = n / 26; unit = firstUnit.toChar() + secondUnit.toChar(); |

That’s all there is to it. And here is the implementation in C#:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public static class CalcUtils { private static readonly int charA = Convert.ToInt32('a'); private static readonly Dictionary<int, string> units = new Dictionary<int, string> { {0, ""}, {1, "K"}, {2, "M"}, {3, "B"}, {4, "T"} }; public static string FormatNumber(double value) { if (value < 1d) { return "0"; } var n = (int) Math.Log(value, 1000); var m = value / Math.Pow(1000, n); var unit = ""; if (n < units.Count) { unit = units[n]; } else { var unitInt = n - units.Count; var secondUnit = unitInt % 26; var firstUnit = unitInt / 26; unit = Convert.ToChar(firstUnit + charA).ToString() + Convert.ToChar(secondUnit + charA).ToString(); } // Math.Floor(m * 100) / 100) fixes rounding errors return (Math.Floor(m * 100) / 100).ToString("0.##") + unit; } } |