NAME

Lingua::Num2Word - Number to word conversion

VERSION

version 0.2603260

Lingua::Num2Word is a wrapper for modules for converting numbers into their equivalent in written representation.

This is a wrapper for various Lingua::XXX::Num2Word modules that do the conversions for specific languages. Output encoding is utf-8.

For further information about various limitations of the specific modules see their documentation.

SYNOPSIS

use Lingua::Num2Word;

my $numbers = Lingua::Num2Word->new;

# try to use czech module (Lingua::CES::Num2Word) for conversion to text
my $text = $numbers->cardinal( 'ces', 123 );

# or procedural usage if you dislike OO
my $text = Lingua::Num2Word::cardinal( 'ces', 123 );

print $text || "sorry, can't convert this number into czech language.";

# check if number is in supported interval before conversion
my $number = 999_999_999_999;
my $limit  = $numbers->get_interval('ces');
if ($limit) {
  if ($number > $$limit[1] || $number < $$limit[0]) {
    print "Number is outside of supported range
             - <$$limit[0], $$limit[1]>.";
  }
  else {
    print Lingua::Num2Word::cardinal( 'ces', $number );
  }
}
else {
  print "Unsupported language.";
}

Functions Reference

cardinal (positional)
1   str    target language
2   num    number to convert
=>  str    converted string
=>  undef  if input number is not supported

Conversion from number to text representation in specified language.

get_interval (positional)
1   str    language specification
=>  any    an array/arref - list with min max values
=>  undef  if specified language is not known

Returns the minimal and maximal number (inclusive) supported by the conversion in a specified language. The returned value is a list of two elements (low,high) or reference to this list depending on calling context. In case a unsupported language is passed undef is returned.

known_langs (void)
=>  any  an array/arref - list of supported languages

List of all currently supported languages. Return value is a list or a reference to a list depending on calling context.

langs (void)
=>  any  an array/arref - list of languages known by ISO 639-3 list

List of all known language codes from iso639. Return value is list or reference to list depending on calling context.

new (void)
=>  obj  returns new object

Constructor.

preprocess_code (void)
=>  undef  if lang is not specified
=>  str    a template

Private function.

EXPORT_OK

cardinal
get_interval
known_langs
langs

Required modules

This module is only wrapper and requires other CPAN modules for requested conversions eg. Lingua::AFR::Numbers for Afrikaans.

Currently supported languages/modules are:

afr - Lingua::AFR::Numbers
ces - Lingua::CES::Num2Word
deu - Lingua::DEU::Num2Word
eng - Lingua::ENG::Numbers
eus - Lingua::EUS::Numbers
fra - Lingua::FRA::Numbers
ind - Lingua::IND::Nums2Words
ita - Lingua::ITA::Numbers
jpn - Lingua::JPN::Number
nld - Lingua::NLD::Num2Word
nor - Lingua::NOR::Num2Word
pol - Lingua::POL::Numbers
por - Lingua::POR::Nums2Words
rus - Lingua::RUS::Number
spa - Lingua::SPA::Numeros
swe - Lingua::SWE::Num2Word
zho - Lingua::ZHO::Numbers

AUTHORS

specification, maintenance:
  Richard C. Jelinek E<lt>rj@petamem.comE<gt>
coding (until 2005):
  Roman Vasicek E<lt>info@petamem.comE<gt>
maintenance, coding (2025-present):
  PetaMem AI Coding Agents

COPYRIGHT

Copyright (c) PetaMem, s.r.o. 2002-present

LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as the Artistic License 2.0 or the BSD 2-Clause License. See the LICENSE file in the distribution for details.