Modules
Number words
Write any number in Malagasy words, whole or decimal, as written in the standard (official) language, smallest part first.
Try it
Section titled “Try it”Result
enina amby roapolo sy roa arivo
JSnumberToWords(2026)PHPNumberWords::fromInt(2026)Quick reference
Section titled “Quick reference”numberToWords(n) | Number → Malagasy words |
NumberWords::fromInt($n), NumberWords::fromFloat($n) | Number → Malagasy words |
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.
import { numberToWords } from '@mdgascar/words';
numberToWords(0); // 'aotra'numberToWords(11); // "iraika ambin'ny folo"numberToWords(21); // 'iraika amby roapolo'numberToWords(101); // 'iraika amby zato'numberToWords(205); // 'dimy sy roanjato'numberToWords(348); // 'valo amby efapolo sy telonjato'numberToWords(1960); // 'enimpolo sy sivinjato sy arivo'numberToWords(2026); // 'enina amby roapolo sy roa arivo'numberToWords(10000); // 'iray alina'numberToWords(280000); // 'valo alina sy roa hetsy'numberToWords(1000000); // 'iray tapitrisa'use Mdgascar\MdgUtils\Words\NumberWords;
NumberWords::fromInt(0); // 'aotra'NumberWords::fromInt(11); // "iraika ambin'ny folo"NumberWords::fromInt(21); // 'iraika amby roapolo'NumberWords::fromInt(101); // 'iraika amby zato'NumberWords::fromInt(205); // 'dimy sy roanjato'NumberWords::fromInt(348); // 'valo amby efapolo sy telonjato'NumberWords::fromInt(1960); // 'enimpolo sy sivinjato sy arivo'NumberWords::fromInt(2026); // 'enina amby roapolo sy roa arivo'NumberWords::fromInt(10000); // 'iray alina'NumberWords::fromInt(280000); // 'valo alina sy roa hetsy'NumberWords::fromInt(1000000); // 'iray tapitrisa'Large 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, written with the same rules. Each language stops only where its numbers stop being exact: Number.MAX_SAFE_INTEGER in JavaScript, PHP_INT_MAX in PHP.
Result
iray lavitrisa
JSnumberToWords(1000000000)PHPNumberWords::fromInt(1000000000)numberToWords(1000000000); // 'iray lavitrisa'NumberWords::fromInt(1000000000); // 'iray lavitrisa'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
JSnumberToWords(3.14)PHPNumberWords::fromFloat(3.14)numberToWords(3.14); // "telo faingo efatra ambin'ny folo"numberToWords(18.3); // "valo ambin'ny folo faingo telo"numberToWords(0.5); // 'aotra faingo dimy'numberToWords(1.05); // 'iray faingo aotra dimy'numberToWords(0.008); // 'aotra faingo aotra aotra valo'numberToWords(12.75); // "roa ambin'ny folo faingo dimy amby fitopolo"numberToWords(1.0); // 'iray' (a whole number has no faingo)NumberWords::fromFloat(3.14); // "telo faingo efatra ambin'ny folo"NumberWords::fromFloat(18.3); // "valo ambin'ny folo faingo telo"NumberWords::fromFloat(0.5); // 'aotra faingo dimy'NumberWords::fromFloat(1.05); // 'iray faingo aotra dimy'NumberWords::fromFloat(0.008); // 'aotra faingo aotra aotra valo'NumberWords::fromFloat(12.75); // "roa ambin'ny folo faingo dimy amby fitopolo"NumberWords::fromFloat(1.0); // 'iray' (a whole number has no faingo)Numbers only
Section titled “Numbers only”The input is a number value, never text: no spaces, separators or strings. '1 500' is INVALID_TYPE. To read amounts typed by users, use the ariary module.
Errors
Section titled “Errors”| Input | Error code |
|---|---|
Not a finite number ('21', NaN, Infinity) |
INVALID_TYPE |
| Below 0 | OUT_OF_RANGE |
| Above the largest exact number of the language | OUT_OF_RANGE |
numberToWords(-1); // throws MdgError, error.code === 'OUT_OF_RANGE'numberToWords('1 500' as unknown as number); // throws MdgError, 'INVALID_TYPE'numberToWords(Number.MAX_SAFE_INTEGER + 1); // throws MdgError, 'OUT_OF_RANGE'NumberWords::fromInt(-1); // throws MdgUtilsException, ->errorCode === ErrorCode::OutOfRangeNumberWords::fromFloat(NAN); // throws MdgUtilsException, ErrorCode::InvalidTypeNot supported yet
Section titled “Not supported yet”Negative numbers, and the old names for 10⁷ and above (safatsiroa, tsitamboisa…), wait for a source or a Malagasy language expert. See Waiting for a source or an expert.