Persian Tools - v4.0.4
    Preparing search index...

    Function wordsToNumber

    • Converts Persian words (e.g., "سیصد و پنجاه هزار") into a number.

      • Optionally fixes fuzzy typos.
      • Removes ordinal suffixes (like "یکم") before parsing.
      • Applies comma formatting and digit conversion (fa/ar/en).

      Type Parameters

      • TResult extends string | number

      Parameters

      • words: string

        Persian string describing a number (e.g., "منفی سیصد و دوازده هزار").

      • config: WordsToNumberOptions = {}

        Options controlling digit style, commas, and fuzzy replacement.

      Returns TResult

      The converted result as either a string or number, depending on options/digits.

        // "سه صد و پنجاه" => 350
      wordsToNumber("سه صد و پنجاه"); // 350

      // Negative example
      wordsToNumber("منفی سه صد و پنجاه"); // -350

      // With commas and Arabic digits
      wordsToNumber("یک میلیون و پانصد هزار", { digits: "ar", addCommas: true });
      // => "١,٥٠٠,٠٠٠"