Modules
Number words
Write any number in Malagasy words, whole or decimal, as written in the standard (official) language, smallest part first.
At a glance
Section titled “At a glance”spell(21)iraika amby roapolospell(2026)enina amby roapolo sy roa arivospell(1000000)iray tapitrisa
Try it
Section titled “Try it”Result
enina amby roapolo sy roa arivo
JSspell(2026)PHPNumberWords::spell(2026)Quick reference
Section titled “Quick reference”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 |
Basic usage
Section titled “Basic usage”Malagasy reads numbers from the smallest part up. The smaller part joins 10 with ambin'ny, 20–90 and exactly 100 with amby, and 200–900 and every larger group with 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'Ordinals
Section titled “Ordinals”spellOrdinal writes the rank: faha before the number in words, fah before a vowel, and voalohany for 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"Reading words back
Section titled “Reading words back”parseWords turns the words back into the number. Case and extra spaces do not matter. safeParseWords returns the error instead of throwing, and tryParseWords returns undefined (PHP: safeParse, tryParse).
Result
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.5Large numbers
Section titled “Large numbers”There is no upper limit in the rules: lavitrisa (10⁹), the largest group word, takes a count of any size. A count before a group word is one phrase joined by amby. Each language stops only where its numbers stop being exact: Number.MAX_SAFE_INTEGER in JavaScript, PHP_INT_MAX in PHP.
spell(280000000); // 'valopolo amby roanjato tapitrisa'spell(1000000000); // 'iray lavitrisa'NumberWords::spell(280000000); // 'valopolo amby roanjato tapitrisa'NumberWords::spell(1000000000); // 'iray lavitrisa'Traditional system
Section titled “Traditional system”Malagasy also has a name for every power of ten. It is not used in everyday writing, but learner books list it. Pass system: 'traditional' to use it: each name takes a single digit, 1 to 9, smallest part first, joined by sy. Below 10 000 both systems write the same words, and decimals follow the system you choose.
| Power | Name | Power | Name | Power | Name |
|---|---|---|---|---|---|
| 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* |
* Derived from the source’s rule: <name>faharoa (“the second”) is that name × 10⁷.
| Case | Call | Result |
|---|---|---|
| standard | spell(30000000) | telopolo tapitrisa |
| traditional | spell(30000000, { system: 'traditional' }) | telo safatsiroa |
Result
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'Decimals
Section titled “Decimals”The whole part comes first, then faingo (the comma), then the digits after the point read as a whole number. Each zero right after the point is aotra.
Result
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"Errors
Section titled “Errors”| Input | Error code |
|---|---|
Not a finite number or text (null, NaN, Infinity) |
INVALID_TYPE |
Text that is not plain decimal ('1 500', '-1', '1e5') |
INVALID_FORMAT |
| Below 0 | OUT_OF_RANGE |
| Above the largest exact number of the language | OUT_OF_RANGE |
parseWords: words that spell does not write |
INVALID_FORMAT |
parseWords: a number too big for the language |
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::InvalidFormatNot supported
Section titled “Not supported”Negative numbers are not written in words: no source spells one.