This template gives the numeric value of the digit in a particular position. It gives the empty string for positions to the left of the number. It tries to detect the number of decimals, giving the empty string for positions to the right of the number.

  • The first parameteris the number.
  • The second parameter is the position of the digit to be produced, where one unit represents 10^position (0 just left of the decimal point, -1 just right of it, etc.

A number like 1234.5678 is a borderline case between this and 1234,5677999... Since results for the various positions are usually used in combination, e.g. for formatting the number in a template like Template:Formatnum, consistency in a borderline case is important, so, in the example, not giving 8 as 4th decimal and 9 as 5th. A secondary objective is to try to avoid giving for 1234.5678 the digits of 1234.5677999...

In a template like formatnum it may or may not be useful to use nesting in the treatment of the decimals, ensuring that after deciding for a particular decimal position that it is beyond the last digit, so the empty string is produced, further positions are not considered. This may be useful for consistency and efficiency, or it may not be needed and better be avoided because of the limit on the expansion depth.

Examples edit

  • {{dig|1234.5678|-14}} gives 0 [1]
  • {{dig|1234.5678|-13}} gives 0 [2]
  • {{dig|1234.5678|-12}} gives 0 [3]
  • {{dig|1234.5678|-11}} gives 0 [4]
  • {{dig|1234.5678|-10}} gives 0 [5]
  • {{dig|1234.5678|-9}} gives 0 [6]
  • {{dig|1234.5678|-8}} gives 0 [7]
  • {{dig|1234.5678|-7}} gives 0 [8]
  • {{dig|1234.5678|-6}} gives 0 [9]
  • {{dig|1234.5678|-5}} gives 0 [10]
  • {{dig|1234.5678|-4}} gives 8 [11]
  • {{dig|1234.5678|-3}} gives 7 [12]
  • {{dig|1234.5678|-2}} gives 6 [13]
  • {{dig|1234.5678|-1}} gives 5 [14]
  • {{dig|1234.5678|0}} gives 4 [15]
  • {{dig|1234.5678|1}} gives 3 [16]
  • {{dig|1234.5678|2}} gives 2 [17]
  • {{dig|1234.5678|3}} gives 1 [18]
  • {{dig|1234.5678|4}} gives 0 [19]
  • {{dig|1234.5678|5}} gives 0 [20]
  • {{dig|1234.5678|6}} gives 0 [21]
  • {{dig|1234.5678|7}} gives 0 [22]
  • {{dig|1234.5678|8}} gives 0 [23]
  • {{dig|1234.5678|9}} gives 0 [24]
  • {{dig|1234.5678|10}} gives 0 [25]
  • {{dig|1234.5678|11}} gives 0 [26]
  • {{dig|1234.5678|12}} gives 0 [27]
  • {{dig|1234.5678|13}} gives 0 [28]
  • {{dig|1234.5678|14}} gives 0 [29]