I need a Perl script which takes numbers as input example 222 and it should output as two hundred twenty two.
A:
Here is one:
Description: This basically converts a number into words. It can only convert numbers less than or equal of novemdecillion quantity. It has a complete input validation process.
Sarfraz
2010-10-26 07:08:35
Thanks for the link..it does the job, now I am going to learn the logic behind it :)
Krishna
2010-10-26 07:37:15
@Krishna: Welcome :)
Sarfraz
2010-10-26 07:38:32
my guess the down vote is for not suggesting a CPAN module but instead old code of a very low quality: just skimming it shows the liberal use of goto, insane regexp to validate the input, no unwrapping of function arguments whatsoever... OTOH if the idea is to get someone asking for us to do their homework to get a bad grade, then that should do the trick.
mirod
2010-10-26 16:11:38
+7
A:
Number::Spell can help you:
use Number::Spell;
my $str = spell_number(222);
eumiro
2010-10-26 07:09:14
A:
Try this. From the author...
You can use this freely and modify it however you want.
Laramie
2010-10-26 07:11:04
Maybe the downvote was for the broken link. Remove `Blockquote` from the end to fix.
Emilio Silva
2010-10-27 03:27:31
+10
A:
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 documentation of the module then you will find that the module also support the following things like,
- It can handle integers like "12" or "-3" and real numbers like "53.19".
- It also understands exponential notation -- it turns "4E9" into "four times ten to the ninth.
- It turns "INF", "-INF", "NaN" into "infinity", "negative infinity", and "not a number", respectively.
Nikhil Jain
2010-10-26 07:27:38