Get the i-th digit of an integer number, counting from the right and starting at 1.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | number |
The integer whose digit is to be extracted. |
||
| integer, | intent(in) | :: | position |
The position of the digit to extract, counting from the right and starting at 1. |
integer pure function get_digit(number, position) result(res) !! Get the `i`-th digit of an integer `number`, counting from the right and starting at 1. integer, intent(in) :: number !! The integer whose digit is to be extracted. integer, intent(in) :: position !! The position of the digit to extract, counting from the right and starting at 1. res = mod(abs(number)/(10**(position - 1)), 10) end function get_digit