itri(3f) - [M_strings:CONVERSION] convert INTEGER to CHARACTER with value grouped into periods of three digits (LICENSE:MIT)
Synopsis
Characteristics
Description
Options
Returns
Examples
Author
License
function itri(in,separator) return(out)
integer(kind=**),intent(in) :: in character(len=*),intent(in),optional :: separator character(len=:),allocatable :: out ! or integer,(kind=**)intent(in) :: in(:) character(len=1),intent(in),optional :: separator character(len=:),allocatable :: out(:)
o IN is a scalar or array INTEGER variable o SEPARATOR is a character string o OUT is a character scalar or array, but the same as IN
Separating large numbers into groups of three digits is called "using periods". Each three-digit group is known as a period (e.g., ones, thousands, millions). The symbol used to separate these groups is typically called a thousands separator or digit group separator (commonly
a comma or space). This is sometimes referred to as periodicity.
Periods: The groups themselves, separated by commas in this case(e.g., 123,456,789).
Purpose: To make large numbers easier to read and understand based on place value.
Other Methods: The International System of Units (SI) recommends using a small space to separate groups of three instead of commas.
Formatting: While English-speaking countries use commas (100,000),
many other countries use periods (ie. decimal points) or spaces (100.000 or 100 000).
o IN : An INTEGER to convert to a string representing the value grouped into periods. o SEPARATOR : Character to use to separate period groups. Defaults to comma (","). Multibyte characters are only supported if IN is scalar.
o OUT : If IN is a scalar a trimmed string is returned. If IN is an array, strings are right-justified in a string long enough to hold all values of the kind of the input.
Sample program
program demo_itri use, intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 use M_strings, only : itri implicit none integer :: i integer(kind=int64) :: ival64 character(len=*),parameter :: braces=(*(:"[",g0,"]",1x)) character(len=*),parameter :: brace=(:"[",g0,"]") ival64=1 ! scalars are returned trimmed of spaces do i=1,19 write(*,braces)itri(ival64),itri(-ival64) ival64=ival64*10+mod(i+1,10) enddo ! arrays are all returned right-justified ! and long enough to fit values of that kind write(*,brace) itri([10_int64, 123456890_int64, -huge(0_int64)]) write(*,brace) itri([10, 123456890, -huge(0)]) write(*,brace) itri([10_int16, 12345_int16, -huge(0_int16)]) write(*,brace) itri([10_int8, 123_int8, -huge(0_int8)])Results:ival64=-huge(0_int64) write(*,brace) & & itri(ival64,separator= ), & & itri(ival64,separator=char(int(zB7))) ! CenterDot 183 U+B7 end program demo_itri
> [1] [-1] > [12] [-12] > [123] [-123] > [1,234] [-1,234] > [12,345] [-12,345] > [123,456] [-123,456] > [1,234,567] [-1,234,567] > [12,345,678] [-12,345,678] > [123,456,789] [-123,456,789] > [1,234,567,890] [-1,234,567,890] > [12,345,678,901] [-12,345,678,901] > [123,456,789,012] [-123,456,789,012] > [1,234,567,890,123] [-1,234,567,890,123] > [12,345,678,901,234] [-12,345,678,901,234] > [123,456,789,012,345] [-123,456,789,012,345] > [1,234,567,890,123,456] [-1,234,567,890,123,456] > [12,345,678,901,234,567] [-12,345,678,901,234,567] > [123,456,789,012,345,678] [-123,456,789,012,345,678] > [1,234,567,890,123,456,789] [-1,234,567,890,123,456,789] > [ 10] > [ 123,456,890] > [-9,223,372,036,854,775,807] > [ 10] > [ 123,456,890] > [-2,147,483,647] > [ 10] > [ 12,345] > [-32,767] > [ 10] > [ 123] > [-127] > [-9 223 372 036 854 775 807] > [-9·223·372·036·854·775·807]
o John S. Urban
