如何在Perl中将数字转换为英文形式?

Vam*_*a B 3 perl cpan numbers perl-module

我需要一个Perl脚本,它将数字作为输入示例222,它应该输出为二百二十二.

Nik*_*ain 15

使用Lingua :: EN :: Numbers - 将"407"变成"四百七十"等.

use Lingua::EN::Numbers qw(num2en num2en_ordinal);

    my $x = 234;
    my $y = 54;
    print "You have ", num2en($x), " things to do today!\n";
    print "You will stop caring after the ", num2en_ordinal($y), ".\n";
Run Code Online (Sandbox Code Playgroud)

打印:

You have two hundred and thirty-four things to do today!
You will stop caring after the fifty-fourth.
Run Code Online (Sandbox Code Playgroud)

如果您阅读该模块的文档,那么您会发现该模块还支持以下内容,例如:

  • 它可以处理像"12"或"-3"这样的整数和像"53.19"那样的实数.
  • 它也理解指数表示法 - 它将"4E9"变成"四次十到九次".
  • 它将"INF"," - INF","NaN"分别变为"无穷大","负无穷大"和"非数字".


eum*_*iro 9

Number :: Spell可以帮到你:

use Number::Spell;
my $str = spell_number(222);
Run Code Online (Sandbox Code Playgroud)