如何填充前导零的FORTRAN浮点输出? [英] How to pad FORTRAN floating point output with leading zeros?

查看:1385
本文介绍了如何填充前导零的FORTRAN浮点输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些浮点数,我需要用FORTRAN输出。假设最大数量可以是999.9999。他们都是非负面的。例如,如果我有25.6893782,245.354567和1.2345678,我需要打印出来的形式如$ /

  025.6894 
245.3546
001.2346



<任何人都知道一个方法来做到这一点?我在网上找到了这方面的一些讨论,但我还没有找到一个干净的方式来做到这一点。如果我知道所有的数字都在10到99之间,用T编辑描述符就相当容易了。但提前无法知道。谢谢。

解决方案

这适用于我

code> real :: areal

然后

  write(*,'(i3.3,f0.6)')int(areal),areal-int(areal)


I have some floating point numbers that I need to output with FORTRAN. Let's say the maximum number could be 999.9999. They are all non-negative. I need zero-padding in front of all numbers less than 100. 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

Anyone know of a way to do this? I have found some discussion of this on the internet, but I haven't found a clean way to do it. 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 to know that ahead of time. Thanks.

解决方案

This works for me

real :: areal

then

write(*,'(i3.3,f0.6)') int(areal),areal-int(areal)

这篇关于如何填充前导零的FORTRAN浮点输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆