How can I printf a Perl bignum without losing precision?

瘦欲@ 提交于 2019-12-04 12:19:18
oylenshpeegul

Perl's printf doesn't really do bignums. Use one of the Math::BigFloat methods for getting a string. Since doing

my $x = $s;

just copies the string, you'll have to do something like

my $x = 0+$s; 

so that $x is a Math::BigFloat. Then something like

printf "%29s\n", $x->ffround(-9);

should do what you want.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!