How can I convert between scientific and decimal notation in Perl?

前端 未结 2 1085
刺人心
刺人心 2021-01-18 07:04

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

2条回答
  •  梦谈多话
    2021-01-18 07:46

    On a related theme, if you want to convert between decimal notation and engineering notation (which is a version of scientific notation), the Number::FormatEng module from CPAN is handy:

    use Number::FormatEng qw(:all);
    print format_eng(1234);     # prints 1.234e3
    print format_pref(-0.035);  # prints -35m
    unformat_pref('1.23T');     # returns 1.23e+12
    

提交回复
热议问题