如何格式化整数以使其仅具有所需的大小? [英] How to format an integer to have only the needed size?

查看:45
本文介绍了如何格式化整数以使其仅具有所需的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试验以下代码:

I have been experimenting with the following code:

program hello
    write(*,"(i9)") 10
end program hello

并改变格式字符串,试图使写入输出的字符串大小正好代表整数,但到目前为止我无法管理它.如何在 Fortran 中编写适合"整数?

and varying the format string, trying to make write output a string just the size needed to represent the integer number, but so far I was unable to manage it. How to write 'fit' integers in Fortran?

推荐答案

I0 编辑描述符是输出具有正确宽度的整数的正确方法.这是在 Fortran 95 中引入的.所有当前的 Fortran 编译器(即 Fortran 90 编译器)都已在 95 年前更新为 Fortran.

A I0 edit descriptor is the correct way for output of integers with the correct width. This was introduced in Fortran 95. All current Fortran compilers which were Fortran 90 compilers have been updated to Fortran 95 years ago.

这篇关于如何格式化整数以使其仅具有所需的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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