From Orain Meta
Jump to navigation Jump to search


The Template:numsense calculates the precision of a number (parameter 1) based on the number sense of how precise the amount has been specified. Contrary to typical engineering precision, where whole multiples of 10 are considered rounded to the nearest 10, this template treats the numbers 10, 20, 30 (etc.) as being rounded to the nearest 1 unit, as precision 0. Examples:

  • {{numsense |23}} Template:Ns→ 0
  • {{numsense |40}} Template:Ns→ 0
  • {{numsense |2300}}  → -2
  • {{numsense |67.00}} → 2
  • {{numsense |59.004500}} → 6

In decimal precision, the number 10 is treated as between 9.5 < 10 < 10.5, rather than 5<10<15. Consequently, {numsense} gives 10, 40, 70 (etc.) the precision 0, same as the numbers 1-9. Also, numerals with trailing zeroes count the extra zeroes as higher precision, so 8.200 has precision 3 for the 3 decimal places.

Performance considerations

In runtime speed, Template:numsense processes numbers at the rate of about 270 numbers per second. For most cases (0-99,000), the expansion depth is only 4 levels of the MediaWiki wp:expansion depth limit, but some numbers over 8 digits might use 6 levels. For simplicity in reviewing the basic algorithm, this template uses markup to handle small numbers, to avoid the complexity of a separate Lua script module using the Scribunto interface to pass data as frame arguments. However, for large amounts, the Lua-based {precision} is invoked from Module:Math.

See also