简体   繁体   English

如何从Perl bignum中获取数字?

[英]How can I get digits out of a Perl bignum?

I have a really big number in Perl. 我在Perl中有一个非常大的数字。 I use "bignum". 我用“bignum”。 How can I extract single digits out of this big number. 如何从这个大数字中提取单个数字。 For example if I have a number like this and what to get the 3rd digit from the end: 例如,如果我有一个这样的数字以及从最后得到第三个数字的内容:

1029384710985234058763045203948520945862986209845729034856 1029384710985234058763045203948520945862986209845729034856

-> 8 - > 8

bignums是透明可用的,所以这将工作:

$digit = substr($bignum, -3, 1);

The bignum package uses Math::BigInt under the hood for integers. bignum包使用Math::BigInt作为整数。

From the Math::BigInt man page: Math::BigInt手册页:

$x->digit($n);        # return the nth digit, counting from right

Note that counting starts at 0 for the rightmost digit. 请注意,对于最右边的数字,计数从0开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM