Re: How to convert integers to characters?



On Sep 29, 12:27 pm, Zbigniew <cblas...@xxxxxxxxx> wrote:
! Fortran 90 code begins
program ex
implicit none
real::a=123.4
character(len=10)::b
write(b,*)a
write(*,"(A8,1X,I3)")b, len_trim(b)
end
! Fortran 90 code ends

Maybe you should write in this way:
write(*,"(A8,1X,I3)") b, trim(adjustl(b))

I'm very sorry for the previous post. There was a mistake.
The correct version is here:

program ex
implicit none
real::a=123.4
character(len=20) :: b ! more space is need is here no 10 but e.g.
20
write(b,"(f5.1)") a
write(*,"(A8,1X,I3)") b, len(trim(adjustl(b)))
end

Compiled gfortan42 and gfortran43, the result is:
$ gfortran42 ex.f95 -o ex
$ ./ex
123.4 5

Best regards,
Zbigniew




Best regards,
Zbigniew


.



Relevant Pages

  • a query !!!
    ... implicit none ...
    (comp.lang.fortran)
  • Re: implicit cast operator funny-ness
    ... describes some weirdness with regards to the implicit casting operator. ... I have a class that can cast implicit to a class that impliments said ... WithOperator to BImpl, and an implicit conversion from BImpl to BI, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Type casting of integer to character in fortran
    ... You need to look up internal files in your textbook: ... IMPLICIT NONE ... Regards, ... Mike Metcalf ...
    (comp.lang.fortran)
  • Re: The need to put "self" in every method
    ... Fernando M. wrote: ... parameter in every method a class has because, if it's always needed, why the obligation to write it? ... couldn't it be implicit? ...
    (comp.lang.python)
  • Re: IMPLICIT NONE (F2k8+/-)
    ... And the victims range from the most novice to the most expert (who despite using IMPLICIT NONE in his own code often has to debug other, lesser, code.) ... It has to do with pragmatism, after 33 years of Fortran experience. ... by shrinking the market by nannying other programmers with whom you simply disagree. ... The compilers will always do so no matter what the standard says. ...
    (comp.lang.fortran)