Compute the number of digits in decimal base of the input integer.
use penf
print FI4P, digit(100_I4P)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I4P), | intent(in) | :: | n | Input integer. |
Number of digits.
elemental function digit_I4(n) result(digit)
!< Compute the number of digits in decimal base of the input integer.
!<
!<```fortran
!< use penf
!< print FI4P, digit(100_I4P)
!<```
!=> 3 <<<
integer(I4P), intent(in) :: n !< Input integer.
character(DI4P) :: str !< Returned string containing input number plus padding zeros.
integer(I4P) :: digit !< Number of digits.
write(str, FI4P) abs(n) ! Casting of n to string.
digit = len_trim(adjustl(str)) ! Calculating the digits number of n.
endfunction digit_I4