Function convertToTakaInWords

  • Converts a number to its word representation in Taka and Poisha.

    Parameters

    • amount: string | number

      The amount to convert (can be a number or string).

    • inEnglish: boolean = false

      If true, converts the amount to English words. Default is false (converts to Bangla words).

    • addSuffix: boolean = false

      If true, appends "Only." (English) or "মাত্র।" (Bangla) at the end. Default is false.

    • noConnector: boolean = false

      If true, skips the connector between Taka and Poisha. Default is false.

    Returns string

    The amount in words, with Taka and Poisha.

    If the input is not a valid number, is negative, or has more than 2 decimal places.

    // Default behavior (Bangla, no suffix, with connector)
    convertToTakaInWords(123.45); // "একশত তেইশ টাকা এবং পঁয়তাল্লিশ পয়সা"
    convertToTakaInWords("১২৩.৪৫"); // "একশত তেইশ টাকা এবং পঁয়তাল্লিশ পয়সা"
    convertToTakaInWords(1000); // "এক হাজার টাকা"
    convertToTakaInWords("১০০০.০০"); // "এক হাজার টাকা"

    // English words
    convertToTakaInWords(123.45, true); // "One hundred twenty-three taka and forty-five poisha"
    convertToTakaInWords("১২৩.৪৫", true); // "One hundred twenty-three taka and forty-five poisha"
    convertToTakaInWords(1000, true); // "One thousand taka"
    convertToTakaInWords("১০০০.০০", true); // "One thousand taka"

    // With suffix
    convertToTakaInWords(123.45, false, true); // "একশত তেইশ টাকা এবং পঁয়তাল্লিশ পয়সা মাত্র।"
    convertToTakaInWords(123.45, true, true); // "One hundred twenty-three taka and forty-five poisha only."
    convertToTakaInWords(1000, false, true); // "এক হাজার টাকা মাত্র।"
    convertToTakaInWords(1000, true, true); // "One thousand taka only."

    // Without connector
    convertToTakaInWords(123.45, false, false, true); // "একশত তেইশ টাকা পঁয়তাল্লিশ পয়সা"
    convertToTakaInWords(123.45, true, false, true); // "One hundred twenty-three taka forty-five poisha"
    convertToTakaInWords(1000, false, false, true); // "এক হাজার টাকা"
    convertToTakaInWords(1000, true, false, true); // "One thousand taka"

    // With suffix and without connector
    convertToTakaInWords(123.45, false, true, true); // "একশত তেইশ টাকা পঁয়তাল্লিশ পয়সা মাত্র।"
    convertToTakaInWords(123.45, true, true, true); // "One hundred twenty-three taka forty-five poisha only."
    convertToTakaInWords(1000, false, true, true); // "এক হাজার টাকা মাত্র।"
    convertToTakaInWords(1000, true, true, true); // "One thousand taka only."

    // Edge cases and error handling
    convertToTakaInWords("১২৩.৪৫২"); // Throws error: "Poisha part cannot exceed 2 digits."
    convertToTakaInWords("-123.45"); // Throws error: "Negative amounts are not allowed."
    convertToTakaInWords("invalid"); // Throws error: "Invalid input: Input must be a valid number string."