如何在Perl中使用科学和十进制表示法进行转换?
发布时间:2020-12-15 23:35:43 所属栏目:大数据 来源:网络整理
导读:我知道这是一个全新的问题,但对许多新程序员来说,答案可能并不明显.这对我来说最初并不明显,所以我在互联网上搜索Perl模块来完成这个简单的任务. 解决方法 sprintf就可以了 use strict;use warnings;my $decimal_notation = 10 / 3;my $scientific_notation
我知道这是一个全新的问题,但对许多新程序员来说,答案可能并不明显.这对我来说最初并不明显,所以我在互联网上搜索Perl模块来完成这个简单的任务.
解决方法
sprintf就可以了
use strict; use warnings; my $decimal_notation = 10 / 3; my $scientific_notation = sprintf("%e",$decimal_notation); print "Decimal ($decimal_notation) to scientific ($scientific_notation)nn"; $scientific_notation = "1.23456789e+001"; $decimal_notation = sprintf("%.10g",$scientific_notation); print "Scientific ($scientific_notation) to decimal ($decimal_notation)nn"; 生成此输出: Decimal (3.33333333333333) to scientific (3.333333e+000) Scientific (1.23456789e+001) to decimal (12.3456789) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |