💥Conversion Functions

A set of functions can be utilized to convert numbers between their Arabic text representation and their numerical form.

Table of Contents

text2number

Syntax

text2number(text)

Description

Converts a given Arabic text representation of a number into its numerical form. The input text should be a string containing Arabic words representing a number.

Parameters

  • text (string) - The input Arabic text representing a number.

Returns

  • number - The numerical form of the given Arabic text.

Example

const text = "خمسة عشر";
const number = text2number(text);
console.log(number); // 15

number2text

Syntax

number2text(anumber)

Description

Converts a given number into its Arabic text representation. The input can be a number or a string containing a number.

Parameters

  • anumber (number | string) - The input number or a string containing a number.

Returns

  • string - The Arabic text representation of the given number.

Example

const anumber = 23;
const text = number2text(anumber);
console.log(text); // "ثلاثة وعشرون"

number2ordinal

Syntax

number2ordinal(anumber, feminin = false);

Description

Converts a given number to its Arabic ordinal form.

Parameters

  • anumber (number|string): The input number to be converted to its ordinal form.

  • feminin (boolean, optional, default=false): If true, the output ordinal will be in the feminine form.

Returns

  • ordinalString (string): The Arabic ordinal string representation of the input number.

Example

const anumber = 3;
const ordinal = number2ordinal(anumber);
console.log(ordinal); // "الثالث"

const femininOrdinal = number2ordinal(anumber, true);
console.log(femininOrdinal); // "الثالثة"

Last updated