如何用前导零填充 Fortran 浮点输出? [英] How to pad Fortran floating point output with leading zeros?
问题描述
我有一些浮点数需要从 Fortran 程序中输出.假设最大数字可能是 999.9999,它们都是非负数.我需要在所有小于 100 的数字前面补零.
I have some floating point numbers that I need to output from a Fortran program. Let's say the maximum number could be 999.9999 and they are all non-negative. I need zero-padding in front of all numbers less than 100.
例如,如果我有 25.6893782、245.354567 和 1.2345678,我需要以类似的形式将它们打印出来
For instance, if I have 25.6893782, 245.354567, and 1.2345678, I need to print them out in a form something like
025.6894
245.3546
001.2346
我该怎么做?例如,如果我知道所有的数字都在 10 到 99 之间,那么使用 T
编辑描述符会相当容易.但我无法提前知道这一点.
How can I do this? It would be fairly easy with the T
edit descriptor if I knew that, for instance, all numbers would be between 10 and 99, something like that. But there is no way for me to know that ahead of time.
推荐答案
这对我有用
real :: areal
然后
write(*,'(i3.3,f0.6)') int(areal),areal-int(areal)
这篇关于如何用前导零填充 Fortran 浮点输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!