Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

write format problem ( real )

$
0
0

hello, all

I write a simple program for writing real variable.

But  case1 and case 2 has some space in front of the number.

Then I tried using 0PF0.4 format, but it removed the number zero.

Finally I changed real variable to character and print it.

Is there any other way to remove the space before number with number zero?

-------------------------------------------

PROGRAM TEST
REAL :: e=0.1425
CHARACTER(LEN=10) :: rstr1

write (*,*) e                                       !case1
write (*,"(f10.4)") e                           !case2
write (*,"(0PF0.4)") e                        !case3

write (rstr1,"(0PF10.4)") e             
write(*,*) rstr1
write (*,'(a)') trim(adjustl(rstr1))        !case4

END PROGRAM TEST

-------------------------------------------

> ./a.out
  0.1425000
    0.1425
.1425
     0.1425
0.1425

 

-------------------------------------------

 

 


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>