如何在Perl中大量打印? [英] How can I sprintf a big number in Perl?
问题描述
在Windows 32位平台上,我必须阅读一些数字,这是出乎意料的,其值可以高达99,999,999,999,但不能超过。尝试 sprintf(%011d,$ myNum)
会产生一个溢出:-2147483648。
On a Windows 32-bit platform I have to read some numbers that, this was unexpected, can have values as big as 99,999,999,999, but no more. Trying to sprintf("%011d", $myNum)
them outputs an overflow: -2147483648.
我不能使用BigInt模块,因为在这种情况下,我应该深刻地更改代码。我不能将格式作为字符串 sprintf(%011s,$ numero)
来管理,因为减号处理不正确。
I cannot use the BigInt module because in this case I should deeply change the code. I cannot manage the format as string, sprintf("%011s", $numero)
, because the minus sign is incorrectly handled.
我该如何管理?装箱/拆箱会有所帮助吗?
How can I manage this? Could pack/unpack be of some help?
推荐答案
尝试将其格式化为不包含小数部分的浮点数:
Try formatting it as a float with no fraction part:
$ perl -v
This is perl, v5.6.1 built for sun4-solaris
...
$ perl -e 'printf "%011d\n", 99999999999'
-0000000001
$ perl -e 'printf "%011.0f\n", 99999999999'
99999999999
这篇关于如何在Perl中大量打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!