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

前端之家收集整理的这篇文章主要介绍了如何在Perl中将数字转换为英文形式?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要一个Perl脚本,它将数字作为输入示例222
它应输出为二百二十二.

解决方法

使用 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";

打印:

You have two hundred and thirty-four things to do today!
You will stop caring after the fifty-fourth.

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

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

猜你在找的Perl相关文章