integer_to_string Function

private function integer_to_string(inumber) result(string)

Converts an integer number to a string. The WRITE statement will return an error message, if the number of digits of the integer number is larger the than the length of the supplied string.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: inumber

Return Value character(len=:), ALLOCATABLE


Source Code

   FUNCTION integer_to_string(inumber) RESULT(string)
      !! Converts an integer number to a string.
      !! The WRITE statement will return an error message, if the number of
      !! digits of the integer number is larger the than the length of the
      !! supplied string.

      INTEGER, INTENT(IN)                                :: inumber
      CHARACTER(:), ALLOCATABLE                          :: string
      CHARACTER(RANGE(inumber) + 2)                      :: tmp

      WRITE (UNIT=tmp, FMT='(I0)') inumber
      string = TRIM(tmp)
   END FUNCTION integer_to_string