Distinguish Between Different Kinds of "Fractional" Numbers [VA6]
Tip VA6
There are many different kinds of “fractional” numbers - numbers representing less than a “whole” in some way - that can appear in code. Because they can have different implications, it’s important to distinguish between them.
“Decimal” is sometimes used to communicate a number that may have digits after a decimal point. Such terminology should be avoided since it more accurately refers just to the decimal number system and could cause confusion.
The following terms can be useful to distinguish between other kinds of fractional numbers:
Percent or percentage - Reserve these terms for numbers than can range from 0 to 100 (unless true percentages outside that range are expected). People most intuitively understand percentages to be in the range of 0 to 100, so to label a variable as a
percent
would lead to an expectation of that variable holding the value45
for 45% (not0.45
).Fraction, proportion, or ratio - These terms are best used when the value of the number is actually less than a whole number (or may have fractional components greater than a whole number - ex.
1.24
). Exactly which term is best depends on context, though “fraction” tends to be more suitable for values truly less than a whole number, whereas “proportion” or “ratio” can be more intuitively applicable to numbers greater than 1.
Making these distinctions accurately is important for correctness in a codebase. If a number is already a percentage, it shouldn’t need to be multiplied by 100 to make it a percentage - such a multiplication would throw off the value of a variable. For example:
If you’re working in a highly mathematical codebase, you may need to make more precise distinctions between different kinds of numbers.