Lingua...Numeros(3pm)
π Lingua::ES::Numeros π
okay bestie, come closer π«Ά this is the page for Lingua::ES::Numeros, and it lives in the User Contributed Perl Documentation corner of the manual (yes, the 3pm shelf, iykyk). she turns numbers into spanish text and honestly? she ate π
πΈ NAME πΈ
Lingua::ES::Numeros β Translates numbers to spanish text.
that's the whole job description and she does it flawlessly, no cap β¨
β¨ SYNOPSIS β¨
use Lingua::ES::Numeros ":constants";
my $obj = new Lingua::ES::Numeros ('MAYUSCULAS' => 1);
print $obj->cardinal(124856), "\n";
print $obj->real(124856.531), "\n";
$obj->{GENERO} = FEMALE;
print $obj->ordinal(124856), "\n";
π¦ DESCRIPTION π¦
okay so here's the tea β this module supports the translation of cardinal, ordinal and real numbers. and she does integer numbers up to vigintillions β that's 1e120 bestie, absolutely unhinged, I'm obsessed π
and here's the thing that makes her different: since Perl does not handle such numbers natively, the numbers are kept as text strings, because processing does not justify using bigint. (she said "why would I pull in a whole bigint situation for this, be serious" π
)
Currently Lingua::ES::Numeros handles numbers up to 1e127-1 (999999 vigintillions). yeah. 999999 of them. main character energy fr fr π
π METHODS π
π CONSTRUCTOR: new
to create a new Lingua::ES::Numeros, you use the new class method π this method can receive as parameters any of the above mentioned fields.
Examples:
use Lingua::ES::Numeros ':constants';
# Use the fields' default values
$obj = new Lingua::ES::Numeros;
# Specifies the values of some of them
$obj = Lingua::ES::Numeros->new( ACENTOS => 0,
MAYUSCULAS => 1, GENERO => FEMALE,
DECIMAL => ',', SEPARADORES=> '"_' );
and now the fields themselves, one by one, she's thorough like that πΈ
π DECIMAL
Specifies the character string that will be used to separate the integer from the fractional part of the number to convert. The default value for DECIMAL is '.'
π€ SEPARADORES
Character string including all of the format characters used when representing a number. Every single character in this string will be ignored by the parser when analyzing the number. The default value for SEPARADORES is '_'
π ACENTOS
Affects the way in which the generated string for the translated numbers is given; if it is false, the textual representation will not have any accented characters. The default value for this field is true (with accents).
π MAYUSCULAS
If this is a true value, the textual representation of the number will be an UPPERCASE character string. The default value for this field is false (lowercase).
π HTML
If this is a true value, the textual representation of the number will be a HTML-valid string character (accents will be represented by their respective HTML entities). The default value is 0 (text).
π§ GENERO
The gender of the numbers can be MALE, FEMALE or NEUTRAL, respectively for femenine, masculine or neutral numbers. The default value is MALE.
The following table shows the efect of GENDER on translation of Cardinal and Ordinal numbers:
1β CARDINAL: MALEuno, FEMALEuna, NEUTRALun; ORDINAL: MALEprimero, FEMALEprimera, NEUTRALprimer2β CARDINAL: MALEdos, FEMALEdos, NEUTRALdos; ORDINAL: MALEsegundo, FEMALEsegunda, NEUTRALsegundo3β CARDINAL: MALEtres, FEMALEtres, NEUTRALtres; ORDINAL: MALEtercero, FEMALEtercera, NEUTRALtercer
The constants MALE, FEMALE and NEUTRAL and their spanish counterparts MASCULINO, FEMENINO and NEUTRO, may be imported with the tag ":constants" on module use. periodt β¨
π SEXO
Deprecated option only for backward compatibility, use GENERO instead.
bestie pls, she's deprecated. useGENERO. we're not doingSEXOin 2024 π
1οΈβ£ UNMIL
This field affects only the translation of cardinal numbers. When it is a true value, the number 1000 is translated to 'un mil' (one thousand), otherwise it is translated to the more colloquial 'mil' (thousand). The default value is 1.
β NEGATIVO
Contains the character string with the text to which the negative sign (-) will be translated with. Defaults to 'menos'.
For example: default translation of -5 will yield "menos cinco".
β POSITIVO
Contains the character string with the text to which the positive sign will be translated with. Defaults to ''.
For example: default translation of 5 will yield "cinco".
π FORMATO
A character string specifying how the decimals of a real number are to be translated. Its default value is 'con %2d ctms.' (see the real method).
β¨ Aliases
All the options have the following english aliases.
ACCENTSβ alias forACENTOSUPPERCASEβ alias forMAYUSCULASSEPARATORSβ alias forSEPARADORESGENDERβ alias forGENEROPOSITIVEβ alias forPOSITIVONEGATIVEβ alias forNEGATIVOFORMATβ alias forFORMATO
π’ cardinal
SYNOPSIS:
$text = $obj->cardinal($num)
Parameters
$num : the number.
Description
Translates a cardinal number ($num) to spanish text, translation is performed according to the following object ($obj) settings: DECIMAL, SEPARADORES, SEXO, ACENTOS, MAYUSCULAS, POSITIVO and NEGATIVO.
This method ignores any fraction part of the number ($num). she simply does not see it, it's not her business π
Return Value
Textual representation of the number as a string.
π real
SYNOPSIS:
$text = real($n; $genf, $genm)
Translates the real number ($n) to spanish text.
The optional $genf and $genm parameters are used to specify gender of the fraction part and fraction part magnitude in that order. If $genf is missing it will default to the GENDER option, and $genm will default to the $genf's value.
This translation is affected by the options: DECIMAL, SEPARADORES, GENDER, ACENTOS, MAYUSCULAS, POSITIVO, NEGATIVO and FORMATO.
π Fraction format (FORMATO)
FORMAT option is a formatting string like printf, it is used to format the fractional part before appending it to the integer part. It has the following format specifiers:
%Ns : Formats the fractional part as text with precisiΓ³n of N digits, for example: number '124.345' formatted with string 'CON %s.' will yield the text 'ciento veinticuatro CON trescientas cuarenta y cinco milΓ©simas', and formatted with string 'CON %2s.' will yield 'ciento veinticuatro CON treinta y cuatro centΓ©simas'.
%Nd : Formats the fractional part as a number (no translation), with precision of N digits, veri similar to sprintf's %d format, for example: number '124.045' formatted with 'CON %2d ctms.' will yield: 'ciento veinticuatro CON 04 ctms.'
π ordinal
SYNOPSIS:
$text = $obj->ordinal($num)
Parameters
$num : the number.
Description
Translates an ordinal number ($num) to spanish text, translation is performed according to the following object ($obj) settings: DECIMAL, SEPARADORES, GENERO, ACENTOS, MAYUSCULAS, POSITIVO and NEGATIVO.
This method croacks if $num <= 0 and carps if $num has a fractional part. so like. be normal about your input or she will absolutely let you know π
Return Value
Textual representation of the number as a string.
π¦ Accessors
Each of the options has a setter/getter with the name of the option in lowercase, all the accessors have the following sintax:
Getters
$obj->name_of_option()
Returns the current value of the option.
Setters
$obj->name_of_option( $value )
Sets the option to $value and returns $obj
List of accessors
$obj->accents
$obj->acentos
$obj->uppercase
$obj->mayusculas
$obj->unmil
$obj->html
$obj->decimal
$obj->separators
$obj->separadores
$obj->gender
$obj->genero
$obj->positive
$obj->positivo
$obj->negative
$obj->negativo
$obj->format
$obj->formato
π§ INTERNALS π§
okay bestie, so the functions in this section are generally not used, but they're documented here for completeness. fr fr
β οΈ this is not part of the module's API and it is subject to change. so likeβ¦ look but don't touch, iykyk π
π CARDINAL SUPPORT π
Construction of cardinal numbers
cardinal_e2
SYNOPSIS
cardinal_e2($n, $nn)
PARAMETERS
$nβ the number.$nnβ word stack.
DESCRIPTION
this procedure takes $n (an integer in the range [0 .. 99], not verified) and adds the numbers text translation to $nn (a word stack), on a word by word basis. if $n == 0 nothing is pushed into $nn. π«Ά
cardinal_e3
SYNOPSIS
cardinal_e3($n, $nn)
PARAMETERS
$nβ the number.$nnβ word stack.
DESCRIPTION
this procedure takes $n (an integer in the range [0 .. 99], not verified) and adds the numbers text translation to $nn (a word stack), on a word by word basis. if $n == 0 nothing is pushed into $nn. β¨
cardinal_e6
SYNOPSIS
cardinal_e6($n, $nn, $mag, $un_mil, $postfix)
PARAMETERS
$nβ the number.$nnβ word stack.$magβ magnitude of the number: 1 for millions, 2 for billions, etc.$un_milβ if true, 1000 is translated as"un mil", otherwise"mil".$postfixβ array representing plural & singular magnitude of the number, in this order.
DESCRIPTION
this procedure takes $n, and pushes the numbers text translation into $nn, on a word by word basis, with the proper translated magnitude. if $n == 0 nothing is pushed into $nn. π
cardinal_generic
SYNOPSIS
cardinal_generic($n, $exp, $fmag, $gen)
PARAMETERS
$nβ the number.$expβ exponent.$fmagβ closure to format the 6 digits groups.$genβ gender of the magnitude (optional, defaults toNEUTRAL):FEMALEfor female gender (1 ->una).MALEfor male gender (1 ->uno).NEUTRALfor neutral gender (1 ->un).
DESCRIPTION
this function translates the natural number $n to spanish words, adding gender where needed. πΈ
RETURN VALUE
Translation of $n to spanish text as a list of words.
cardinal_simple
SYNOPSIS
cardinal_simple($n, $exp, $un_mil; $gen)
PARAMETERS
$nβ the number.$expβ exponent.$un_milβ if true, 1000 is translated as"un mil", otherwise"mil".$genβ gender of the magnitude (optional, defaults toNEUTRAL):FEMALEfor female gender (1 ->una).MALEfor male gender (1 ->uno).NEUTRALfor neutral gender (1 ->un).
DESCRIPTION
this function translates the natural number $n to spanish words, adding gender where needed.
this procedure just builds a closure with format information, to call cardinal_e6, and then calls cardinal_generic to do the work. π
RETURN VALUE
Translation of $n to spanish text as a list of words.
fraccion_mag_prefix
SYNOPSIS
fraccion_mag_prefix($mag, $gp)
PARAMETERS
$nβ the number.$expβ exponent.$magβ magnitude of the number: 1 for millionths, 2 for billionths, etc.$gpβ gender and plural of the number; it's the concatenation of gender and plural. gender must be one ofFEMALE,MALEorNEUTRAL, and plural must be''for singular and's'for plural.- note that
NEUTRAL+ plural is a nonsense. π
- note that
$ngenβ gender of the number (same values as$gen).
DESCRIPTION
this function returns the name of the magnitude of a fraction, $mag is the number of decimal digits. for example, 0.001 has $mag == 3 and translates to "milesimos" if $gp is (MALE . 's'). π
RETURN VALUE
Translation of $n to spanish text as a string.
fraccion_simple
SYNOPSIS
fraccion_simple($n, $exp, $un_mil, $gen; $ngen)
PARAMETERS
$nβ the number.$expβ exponent.$un_milβ if true, 1000 is translated as"un mil", otherwise"mil".$genβ gender of the magnitude (optional, defaults toNEUTRAL):FEMALEfor female gender (1 ->primera).MALEfor male gender (1 ->primero).NEUTRALfor neutral gender (1 ->primer).
$ngenβ gender of the number (same values as$gen).
DESCRIPTION
this function translates the fraction $n to spanish words, adding gender where needed.
this procedure just builds a closure with format information, to call cardinal_e6, and then calls cardinal_generic to do the work. π
RETURN VALUE
Translation of $n to spanish text as a list of words.
π’ ORDINAL SUPPORT π’
Construction of ordinal numbers
ordinal_e2
SYNOPSIS
ordinal_e2($n, $nn)
PARAMETERS
$nβ the number.$nnβ word stack.
DESCRIPTION
this procedure takes $n (an integer in the range [0 .. 99], not verified) and adds the numbers text translation to $nn (a word stack), on a word by word basis. if $n == 0 nothing is pushed into $nn. π
ordinal_e3
SYNOPSIS
ordinal_e3($n, $nn)
Parameters
$nβ the number.$nnβ word stack.
DESCRIPTION
this procedure takes $n (an integer in the range [0 .. 999], not verified) and adds the numbers text translation to $nn (a word stack), on a word by word basis. if $n == 0 nothing is pushed into $nn. β
ordinal_e6
SYNOPSIS
ordinal_e6($n, $nn, $mag, $un_mil, $postfix)
PARAMETERS
$nβ the number.$nnβ word stack.$magβ magnitude of the number: 1 for millions, 2 for billions, etc.
DESCRIPTION
this procedure takes $n, and pushes the numbers text translation into $nn, on a word by word basis, with the proper translated magnitude. if $n == 0 nothing is pushed into $nn. π
ordinal_simple
SYNOPSIS
ordinal_simple($n, $exp; $gen)
PARAMETERS
$nβ the number.$expβ exponent.$un_milβ if true, 1000 is translated as"un mil", otherwise"mil".$genβ gender of the magnitude (optional, defaults toNEUTRAL):FEMALEfor female gender (1 ->primera).MALEfor male gender (1 ->primero).NEUTRALfor neutral gender (1 ->primer).
DESCRIPTION
this function translates the fraction $n to spanish words, adding gender where needed.
this procedure just builds a closure with format information, to call ordinal_e6, and then calls ordinal_generic to do the work. π¦
RETURN VALUE
Translation of $n to spanish text as a list of words.
π§ MISCELANEOUS π§
Everything not fitting elsewhere
parse_num
SYNOPSIS
parse_num($num, $dec, $sep)
Decomposes the number in its constitutive parts, and returns them in a list:
use Lingua::ES::Numeros;
($sgn, $ent, $frc, $exp) = parse_num('123.45e10', '.', '",');
PARAMETERS
$numβ the number to decompose.$decβ decimal separator (typically','or'.').$sepβ separator characters ignored by the parser, usually to mark thousands, millions, etc.
RETURN VALUE
this function parses a general number and returns a list of 4 elements:
$sgnβ sign of the number:-1if negative,1otherwise.$intβ integer part of the number.$frcβ decimal (fraction) part of the number.$expβ exponent of the number.
π¨ Croaks if there is a syntax error. like, it will literally just give up on you. π
retval
SYNOPSIS
$obj->retval($value)
DESCRIPTION
utility method to adjust return values, transforms text following the options: ACENTOS, MAYUSCULAS y HTML.
Returns the adjusted $value. π
π¦ DEPENDENCIES π¦
Perl 5.006, Exporter, Carp
π SEE ALSO π
http://roble.pntic.mec.es/~msanto1/ortografia/numeros.htm
π AUTHOR π
Jose Rey, <jrey@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright (C) 2001-2009 by Jose Rey
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
and that's a wrap bestie, no cap π«Ά this whole thing is the perl v5.36.0 build from 2022-11-21, so like, that's the vintage of the Lingua...Numeros(3pm) energy you're getting β go forth and count in spanish, you absolute icon πΈπβ¨
π¦ where this page comes from
- debian bookworm: liblingua-es-numeros-perl 0.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: liblingua-es-numeros-perl 0.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liblingua-es-numeros-perl 0.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblingua-es-numeros-perl 0.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblingua-es-numeros-perl 0.09-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms