本文介绍了如何在Perl中的科学和十进制表示法之间转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这是一个新手问题,但是对于许多新程序员来说,答案可能并不明显。最初对我而言并不明显,所以我在Internet上搜索了Perl模块以完成此简单任务。
I know this is a total newbie question, but the answer may not be obvious to many new programmers. It wasn't initially obvious to me so I scoured the Internet looking for Perl modules to do this simple task.
推荐答案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)\n\n"; $scientific_notation = "1.23456789e+001"; $decimal_notation = sprintf("%.10g", $scientific_notation); print "Scientific ($scientific_notation) to decimal ($decimal_notation)\n\n";生成以下输出:
Decimal (3.33333333333333) to scientific (3.333333e+000) Scientific (1.23456789e+001) to decimal (12.3456789)更多推荐
如何在Perl中的科学和十进制表示法之间转换?
发布评论