Lingua-EN-Numbers

 view release on metacpan or  search on metacpan

lib/Lingua/EN/Numbers.pm  view on Meta::CPAN


  return "$x$last";
}

#==========================================================================

sub num2en {
  my $x = $_[0];
  return undef unless defined $x and length $x;

  return 'not-a-number'      if $x eq 'NaN';
  return 'positive infinity' if $x =~ m/^\+inf(?:inity)?$/si;
  return 'negative infinity' if $x =~ m/^\-inf(?:inity)?$/si;
  return          'infinity' if $x =~  m/^inf(?:inity)?$/si;

  return $D{$x} if exists $D{$x};  # the most common cases

  # Make sure it's not in scientific notation:
  {  my $e = _e2en($x);  return $e if defined $e; }
  
  my $orig = $x;

lib/Lingua/EN/Numbers.pm  view on Meta::CPAN

It also provides a function C<num2en_ordinal>,
which converts a number into the ordinal form in words,
so 54 becomes "fifty-fourth".

If you pass either function something that doesn't look like a number,
they will return C<undef>.

This module can handle integers like "12" or "-3" and real numbers like "53.19".

This module also understands exponential notation -- it turns "4E9" into
"four times ten to the ninth").  And it even turns "INF", "-INF", "NaN"
into "infinity", "negative infinity", and "not a number", respectively.

Any commas in the input numbers are ignored.

=head1 LEGACY INTERFACE

The first version of this module, 0.01 released in May 1995,
had an OO interface. This was finally dropped in the 1.08 release.

=head1 SEE ALSO



( run in 0.304 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )