Template:Getprecision

4

Documentation icon Template documentation[view] [edit] [history] [purge]

The Template:Getprecision determines the precision (as a count of decimal digits) for any amount, large or negative, using a fast algorithm. It can also handle a trailing decimal point (such as "15." or "-41.") or trailing zeroes (such as "15.34000" having precision as 5 decimal digits).

Examples

Some examples:

  • {{getprecision|0}} → 0
  • {{getprecision|1}} → 0
  • {{getprecision|22.5}} → 1
  • {{getprecision|22+1/2}} → 1
  • {{getprecision|22.45}} → 2
  • {{getprecision|22.12345}} → 5
  • {{getprecision|22}} → 0
  • {{getprecision|22000}} → -3
  • {{getprecision|-15.275}} → 3
  • {{getprecision|-15.2500}} → 4
  • {{getprecision|-15-25/100}} → 2
  • {{Getprecision |23000222000111.432}} → 3
  • {{getprecision|-15.123}} → 3
{{precision|-15.123}} → 0 [ Getprecision handles negatives, but not {precision} ]
  • {{getprecision|0.09}} → 2
  • {{getprecision|0.88}} → 2
  • {{getprecision|880000}} → -4
  • {{getprecision|90000000}} → -7

Known bugs

  • Cannot have spaces around a number, as leading spaces or trailing.
  • For numbers in scientific notation, the precision is typically returned as too low by 1 decimal place. Example: {{getprecision |7.1234E+06}} → -2 (should be precision as 4 decimal digits, not 3).
  • Large numbers are limited to 11 trailing zeroes, so even larger numbers still report precision as being -11, such as 9 trillion: {{getprecision|9000000000000}} → -12 (should be: -12).

Related pages