This page records the formula and input rules behind every NumberUtils calculator, written from the calculation code, which is covered by automated tests. Where a calculation has more than one accepted convention, it says which one is used. For explanations of the maths itself, see the guides.

Precision, rounding and display

  • Calculations run in your browser using standard double-precision numbers. Results are tidied to 12 significant digits, which removes floating-point artefacts such as 0.1 + 0.2 showing as 0.30000000000000004.
  • Results are displayed with up to 10 decimal places, with thousands separated by commas. A recurring value such as 1 ÷ 3 is therefore shown as 0.3333333333; it is not exact.
  • Input must be an ordinary number. Text, empty fields and values that are not finite are rejected with a message rather than treated as zero.

Percentages

  • A percentage of a value is value × percentage ÷ 100. One value as a percentage of another is (part ÷ whole) × 100, and the whole cannot be zero.
  • Percentage change is (new − original) ÷ original × 100. It is positive for an increase and negative for a decrease, and the original value cannot be zero.
  • Percentage difference is |a − b| ÷ ((a + b) ÷ 2) × 100. It is symmetric, so the order of the values does not matter, and it is never negative. Both values must be zero or more and they cannot both be zero.
  • Increases use original × (1 + percentage ÷ 100) and decreases use original × (1 − percentage ÷ 100). A negative percentage is accepted and has the same effect as the opposite operation.
  • Reversing a percentage divides by the same multiplier: a value of 120 after a 20% increase started at 120 ÷ 1.2 = 100. A 100% decrease cannot be reversed, because it sends every starting value to zero, so it is rejected.

Ratios and proportions

  • A ratio a : b is simplified by dividing both sides by their greatest common divisor. Decimal sides are first scaled by a power of ten to whole numbers, so 1.5 : 2.5 becomes 15 : 25 and then 3 : 5.
  • Each side's share is its value divided by the total, as a percentage: 2 : 3 is 40% and 60%.
  • Ratio sides must be zero or more, and at least one must be non-zero: a ratio of negative quantities is not a meaningful share of a whole. 0 : 5 simplifies to 0 : 1.
  • A proportion a : b = c : x is solved by cross-multiplication, x = b × c ÷ a. All values must be zero or more, and a cannot be zero because it is the divisor.
  • The ratio calculator works with two-part ratios. Sharing an amount in a ratio with three or more parts is explained in the ratios and proportions guide.

Fractions and conversions

  • Fractions are held as whole-number numerators and denominators throughout a calculation and are always reduced to lowest terms with a positive denominator. A decimal is produced only at the final step, so 1/3 + 1/3 + 1/3 is exactly 1.
  • Negative fractions are ordinary values: −3/4 is accepted. A negative mixed number carries its sign on the whole part, so −2 3/4 means −(2 + 3/4) = −11/4.
  • Numerators, denominators and whole parts must be whole numbers. The denominator cannot be zero, and dividing by a zero fraction is rejected.
  • A decimal is converted to a fraction exactly as typed, using the number of decimal places entered: 0.75 is 75/100 = 3/4, and 0.333 is 333/1000, not 1/3. A percentage is converted the same way: 12.5% is 125/1000 = 1/8.
  • Values with too many decimal places to scale exactly are rejected rather than approximated.

Averages

  • Numbers are entered as a list separated by commas or spaces. At least one number is needed.
  • The mean is the sum divided by the count. The median is the middle value of the sorted list, or the mean of the two middle values when the count is even. The range is the largest value minus the smallest.
  • The mode is the most frequent value. When several values are tied for most frequent, all of them are reported. When every value occurs equally often, including when all values are different, there is no mode.
  • Averages are unweighted: each value entered counts once. To weight a value, enter it as many times as its weight.

Discount, markup and margin

  • Sale price after a discount is price × (1 − discount ÷ 100), and the saving is price − sale price. A discount must be between 0% and 100%, and the price zero or more.
  • Selling price after a markup is cost × (1 + markup ÷ 100). Markup is profit as a percentage of cost; the cost and the markup must both be zero or more.
  • Profit margin is (selling price − cost) ÷ selling price × 100: profit as a percentage of the selling price. A selling price below cost gives a negative margin, which is a loss rather than an error. Cost and selling price must be zero or more, and the selling price cannot be zero.
  • No tax, VAT or currency rounding rules are applied. See markup and profit margin for how the three figures relate.

Factors, primes, GCD and LCM

  • The factors calculator and prime number checker accept whole numbers up to 1,000,000,000,000. Both test divisors only up to the square root of the number.
  • 0, 1 and negative numbers are reported as not prime, since prime numbers are defined as whole numbers greater than 1 with exactly two factors. Decimals are rejected.
  • Factors are listed in ascending order and include 1 and the number itself. The number must be a positive whole number.
  • The greatest common divisor uses Euclid's algorithm. The least common multiple is (a ÷ gcd) × b, dividing before multiplying to keep intermediate values small. Both inputs must be positive whole numbers.

What the calculators do not do

  • They do not apply tax, accounting or legal rules, and they do not round to currency units.
  • They do not calculate weighted averages, standard deviation or other statistics beyond those listed above.

If a result looks wrong, please get in touch.