Fortran formated output for floating point numbers

2019-03-04 09:42发布

Is there a way in Fortran to write float numbers as 17,3 and not 17.3, changing the dot to a comma?

I have some large data sets wirtten to a .csv by a subroutine, and i want to do some Excel on it. The german version of Excel uses . as a seperator in floating point numbers. I know i can use the import feature to handle it, or use Nodepad++ to search and replace . with ,. But i do generate lots of these files, and the subroutine will be used by others, so an Excel ready file would be nice.

1条回答
别忘想泡老子
2楼-- · 2019-03-04 10:03

If you're just writing a line or two you can add the decimal edit descriptor dc to your output format. Here's a simple example

write(*,'(dc,f12.3)') 12.3

which produces

12,300

If you want to write to a file, add the clause

decimal = 'comma'

to your open statement, for example:

open(6,decimal='comma')

Of course, here I'm (re-)opening stdout to write commas rather than points.

查看更多
登录 后发表回答