How to convert a number to its English form in Perl?

I need a Perl script that takes numbers as input 222, and it should print like two hundred twenty two .

+3
source share
4 answers

Use Lingua :: EN :: Numbers - turn "407" into "four hundred and seven", etc.

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

prints:

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

If you read the module documentation, you will find that the module also supports the following functions, such as

  • It can handle integers like "12" or "-3" and real numbers like "53.19".
  • - "4E9" " ".
  • "INF", "-INF", "NaN" "", " " " " .
+15

:: :

use Number::Spell;
my $str = spell_number(222);
+9
-1

this. ...

, .

-2

Source: https://habr.com/ru/post/1771435/


All Articles