Modules
Nombres en lettres
Écrire tout nombre en lettres malgaches, entier ou décimal, selon la langue officielle, de la plus petite unité à la plus grande.
spell(21)iraika amby roapolospell(2026)enina amby roapolo sy roa arivospell(1000000)iray tapitrisa
Résultat
enina amby roapolo sy roa arivo
JSspell(2026)PHPNumberWords::spell(2026)Référence rapide
Section intitulée « Référence rapide »spell(n, options) | Number → Malagasy words |
spellOrdinal(n, options) | Whole number → ordinal words (rule 14) |
parseWords(text, options) | Words → number, or throws (rule 15) |
safeParseWords(text, opts) | Words → number or error code, no throw |
tryParseWords(text, options) | Words → number, or nothing, never throws |
NumberWords::spell($n, $system) (int, float or decimal text) | Number → Malagasy words |
NumberWords::spellOrdinal($n, $system) | Whole number → ordinal words (rule 14) |
NumberWords::parse($text)->value(), ->digits | Words → number, or throws (rule 15) |
NumberWords::safeParse($text) | Words → number or error code, no throw |
NumberWords::tryParse($text) → null | Words → number, or nothing, never throws |
Utilisation de base
Section intitulée « Utilisation de base »Le malgache lit les nombres de la plus petite unité à la plus grande. La partie la plus petite se relie à 10 par ambin'ny, à 20–90 et à 100 exactement par amby, à 200–900 et aux groupes plus grands par sy.
- enina6
- amby
- roapolo20
- sy
- roa arivo2000
enina amby roapolo sy roa arivo
- valo8
- amby
- efapolo40
- sy
- telonjato300
valo amby efapolo sy telonjato
import { spell } from '@mdgascar/number-words';
spell(0); // 'aotra'spell(11); // "iraika ambin'ny folo"spell(21); // 'iraika amby roapolo'spell(101); // 'iraika amby zato'spell(205); // 'dimy sy roanjato'spell(348); // 'valo amby efapolo sy telonjato'spell(1960); // 'enimpolo sy sivinjato sy arivo'spell(2026); // 'enina amby roapolo sy roa arivo'spell(10000); // 'iray alina'spell(280000); // 'valo alina sy roa hetsy'spell(1000000); // 'iray tapitrisa'use Mdgascar\MalagasyIntl\NumberWords\NumberWords;
NumberWords::spell(0); // 'aotra'NumberWords::spell(11); // "iraika ambin'ny folo"NumberWords::spell(21); // 'iraika amby roapolo'NumberWords::spell(101); // 'iraika amby zato'NumberWords::spell(205); // 'dimy sy roanjato'NumberWords::spell(348); // 'valo amby efapolo sy telonjato'NumberWords::spell(1960); // 'enimpolo sy sivinjato sy arivo'NumberWords::spell(2026); // 'enina amby roapolo sy roa arivo'NumberWords::spell(10000); // 'iray alina'NumberWords::spell(280000); // 'valo alina sy roa hetsy'NumberWords::spell(1000000); // 'iray tapitrisa'Ordinaux
Section intitulée « Ordinaux »spellOrdinal écrit le rang : faha devant le nombre en lettres, fah devant une voyelle, et voalohany pour 1.
import { spellOrdinal } from '@mdgascar/number-words';
spellOrdinal(1); // 'voalohany'spellOrdinal(2); // 'faharoa'spellOrdinal(3); // 'fahatelo'spellOrdinal(4); // 'fahefatra'spellOrdinal(11); // "fahiraika ambin'ny folo"NumberWords::spellOrdinal(1); // 'voalohany'NumberWords::spellOrdinal(2); // 'faharoa'NumberWords::spellOrdinal(3); // 'fahatelo'NumberWords::spellOrdinal(4); // 'fahefatra'NumberWords::spellOrdinal(11); // "fahiraika ambin'ny folo"Relire des lettres
Section intitulée « Relire des lettres »parseWords retrouve le nombre à partir des lettres. La casse et les espaces en trop ne comptent pas. safeParseWords renvoie l’erreur au lieu de la lever, et tryParseWords renvoie undefined (PHP : safeParse, tryParse).
Résultat
2026
JSparseWords('enina amby roapolo sy roa arivo')PHPNumberWords::parse('enina amby roapolo sy roa arivo')->value()import { parseWords } from '@mdgascar/number-words';
parseWords('roa arivo'); // 2000parseWords('Iraika amby roapolo'); // 21parseWords('telo faingo dimy'); // 3.5NumberWords::parse('roa arivo')->value(); // 2000NumberWords::parse('Iraika amby roapolo')->value(); // 21NumberWords::parse('telo faingo dimy')->value(); // 3.5Grands nombres
Section intitulée « Grands nombres »Les règles n’ont pas de limite haute : lavitrisa (10⁹), le plus grand mot de groupe, prend un multiplicateur de toute taille. Un multiplicateur devant un mot de groupe forme une seule expression, reliée par amby. Chaque langage s’arrête seulement là où ses nombres cessent d’être exacts : Number.MAX_SAFE_INTEGER en JavaScript, PHP_INT_MAX en PHP.
Résultat
iray lavitrisa
JSspell(1000000000)PHPNumberWords::spell(1000000000)spell(280000000); // 'valopolo amby roanjato tapitrisa'spell(1000000000); // 'iray lavitrisa'NumberWords::spell(280000000); // 'valopolo amby roanjato tapitrisa'NumberWords::spell(1000000000); // 'iray lavitrisa'Système traditionnel
Section intitulée « Système traditionnel »Le malgache a aussi un nom pour chaque puissance de dix. Il ne sert pas dans l’écriture courante, mais les manuels d’apprentissage le donnent. Passez system: 'traditional' pour l’utiliser : chaque nom prend un seul chiffre, de 1 à 9, du plus petit au plus grand, reliés par sy. Sous 10 000, les deux systèmes écrivent les mêmes mots, et les décimales suivent le système choisi.
| Puissance | Nom | Puissance | Nom | Puissance | Nom |
|---|---|---|---|---|---|
| 10⁴ | alina |
10⁹ | lavitrisa |
10¹⁴ | safatsiroafaharoa |
| 10⁵ | hetsy |
10¹⁰ | alinkisa |
10¹⁵ | tsitamboisafaharoa |
| 10⁶ | tapitrisa |
10¹¹ | tsipesimpesenina |
10¹⁶ | lavitrisafaharoa* |
| 10⁷ | safatsiroa |
10¹² | tsitokotsiforohana |
10¹⁷ | alinkisafaharoa* |
| 10⁸ | tsitamboisa |
10¹³ | tsihitanoanoa |
10¹⁸ | tsipesimpeseninafaharoa* |
* Déduits de la règle de la source : <nom>faharoa (« le deuxième ») vaut ce nom × 10⁷.
| Cas | Appel | Résultat |
|---|---|---|
| standard | spell(30000000) | telopolo tapitrisa |
| traditionnel | spell(30000000, { system: 'traditional' }) | telo safatsiroa |
Résultat
telo safatsiroa
JSspell(30000000, { system: 'traditional' })PHPNumberWords::spell(30000000, NumberSystem::Traditional)spell(30000000); // 'telopolo tapitrisa'spell(30000000, { system: 'traditional' }); // 'telo safatsiroa'use Mdgascar\MalagasyIntl\NumberWords\NumberSystem;
NumberWords::spell(30000000); // 'telopolo tapitrisa'NumberWords::spell(30000000, NumberSystem::Traditional); // 'telo safatsiroa'Décimales
Section intitulée « Décimales »La partie entière vient d’abord, puis faingo (la virgule), puis les chiffres après la virgule lus comme un nombre entier. Chaque zéro juste après la virgule se dit aotra.
Résultat
telo faingo efatra ambin'ny folo
JSspell(3.14)PHPNumberWords::spell(3.14)spell(3.14); // "telo faingo efatra ambin'ny folo"spell(0.5); // 'aotra faingo dimy'spell(12.75); // "roa ambin'ny folo faingo dimy amby fitopolo"NumberWords::spell(3.14); // "telo faingo efatra ambin'ny folo"NumberWords::spell(0.5); // 'aotra faingo dimy'NumberWords::spell(12.75); // "roa ambin'ny folo faingo dimy amby fitopolo"| Entrée | Code d’erreur |
|---|---|
Ni un nombre fini ni du texte (null, NaN, Infinity) |
INVALID_TYPE |
Texte qui n’est pas décimal simple ('1 500', '-1', '1e5') |
INVALID_FORMAT |
| Inférieur à 0 | OUT_OF_RANGE |
| Au-delà du plus grand nombre exact du langage | OUT_OF_RANGE |
parseWords : des lettres que spell n’écrit pas |
INVALID_FORMAT |
parseWords : un nombre trop grand pour le langage |
PRECISION_LOSS |
spell(-1); // throws MalagasyIntlError, error.code === 'OUT_OF_RANGE'spell('1 500'); // throws MalagasyIntlError, 'INVALID_FORMAT'NumberWords::spell(-1); // throws MalagasyIntlException, ->errorCode === ErrorCode::OutOfRangeNumberWords::spell(NAN); // throws MalagasyIntlException, ErrorCode::InvalidTypeNumberWords::spell('1 500'); // throws MalagasyIntlException, ErrorCode::InvalidFormatNon pris en charge
Section intitulée « Non pris en charge »Les nombres négatifs ne sont pas écrits en lettres : aucune source n’en épelle un.