Place the decimal point in an already rounded digit string.
The invariant maintained by round_decimal is that n_rounded equals
point_pos + dec whenever any digit survives, so splitting at
point_pos always leaves exactly dec fractional digits.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| logical, | intent(in) | :: | negative | |||
| character(len=*), | intent(in) | :: | rounded | |||
| integer(kind=default_int), | intent(in) | :: | n_rounded | |||
| integer(kind=default_int), | intent(in) | :: | point_pos | |||
| integer(kind=default_int), | intent(in) | :: | dec |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=:), | private, | allocatable | :: | frac_part | |||
| character(len=:), | private, | allocatable | :: | int_part |
pure function assemble_fixed(negative, rounded, n_rounded, point_pos, dec) result(string) !! Place the decimal point in an already rounded digit string. !! !! The invariant maintained by `round_decimal` is that `n_rounded` equals !! `point_pos + dec` whenever any digit survives, so splitting at !! `point_pos` always leaves exactly `dec` fractional digits. logical, intent(in) :: negative character(len=*), intent(in) :: rounded integer(default_int), intent(in) :: n_rounded, point_pos, dec character(len=:), allocatable :: string character(len=:), allocatable :: int_part, frac_part if (n_rounded <= 0_default_int) then int_part = "0" frac_part = repeat("0", dec) else if (point_pos <= 0_default_int) then int_part = "0" frac_part = repeat("0", -point_pos)//rounded(1:n_rounded) else int_part = rounded(1:point_pos) frac_part = rounded(point_pos + 1:n_rounded) end if if (dec > 0_default_int) then string = int_part//"."//frac_part else string = int_part end if if (negative) string = "-"//string end function assemble_fixed