The function str_I2P converts integer to string. This function achieves casting of integer to string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in), | optional | :: | no_sign | ||
integer(kind=I2P), | intent(in) | :: | n |
elemental function str_I2P(no_sign,n) result(str)
!---------------------------------------------------------------------------------------------------------------------------------
!!The function str\_I2P converts integer to string. This function achieves casting of integer to string.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
implicit none
logical, intent(IN), optional:: no_sign ! Flag for leaving out the sign.
integer(I2P), intent(IN):: n ! Integer to be converted.
character(DI2P):: str ! Returned string containing input number plus padding zeros.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
write(str,FI2P) n ! Casting of n to string.
str = adjustl(trim(str)) ! Removing white spaces.
if (n>=0_I2P) str='+'//trim(str) ! Prefixing plus if n>0.
if (present(no_sign)) str=str(2:) ! Leaving out the sign.
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction str_I2P