How to Convert numbers to word in indian Currency Format
Asked Answered
K

1

0

I have A pdf form With this field

1.Invoice
2.Date
3.Truck No 
4.Party Name
5.Party Place 
6.City
7.GSTIN
8.Product
9.HSN
10.QTY
11.Rate
12.Amount
13.CGST
14.SGST
15.Total
16.Number

These are my Form Field

I need to Convert My Number to word By javascript

Example:5279.40=Two Hundred Seventy-Nine and Forty paise

I want to Convert field "Amount" (This is my Numeric Field) To Numbers in "Number" Field

I want Output In Field "NUmber"

I have use a Javscript to Convert this Number

This is My Custum Valiation Script

function ConvertToWords(num)
    {
    var aUnits = [ "Thousand", "Million", "Billion", "Trillion", "Quadrillion" ];
    var cWords = "and ";
    // var cWords = (num >= 1 && num < 2) ? "Dollar and " : "Dollars and "; // use for spelled out words
    var nLeft = Math.floor(num);
    for (var i = 0; nLeft > 0; i++) { 
    if (nLeft % 1000 > 0) {
    if (i != 0)
    cWords = ConvertToHundreds(nLeft) + " " + aUnits[i - 1] + " " + cWords;
    else
    cWords = ConvertToHundreds(nLeft) + " " + cWords;
           }
    nLeft = Math.floor(nLeft / 1000);
       }
    num = Math.round(num * 100) ;
    cWords += util.printf("%,102/100 Dollars", num); // numerical cents
    /* for spelled out cents
    if (num > 0) {
    cWords += ConvertToHundreds(num) + " Cents"; // spelled out cents
    } else {
    cWords += "Zero Cents";
        } 
    */
    return cWords;
    }

I am using A Custum Calculation Script

Below my Custum Calculation Script JavaScript

        var f = this.getField("Total");

    event.value = ConvertToHundreds(f.value);

But this script won't give the Output That I need its does not show the Amount After Decimal in Field("Amount")

As you can see in FFigure 1.1

Figure 1.1

or this code does one more Mistake you Can see In Figure 1.2

Figure 1.2 ("You Can See In "Number" Field Its only Show Forty But my Amount in "Amount" Field is 5040.00 ")

Pls give Me suggestion or a code that is Solve My Problem

Pls dont give me Duplicate of my Question I am Already Search this question on " https://stackoverflow.com" there is no Solution or no Code that Convert Numbers to words In INdian Currency I Found Few of Answer but They Wont work with Indian Currency

Karol answered 3/9, 2018 at 10:24 Comment(3)
Possible duplicate of Convert digits into words with JavaScriptSangfroid
could you add ConvertToHundreds() aswell ?Lolalolande
Yes i add ConvertToHundreds and its work but its output its not that what i wantKarol
F
1

I've used it to convert Indian rupees amount in words with paise value. Basically it works fine with typescript if we generate a pipe in angular 7+ or above. For more information about pipes in angular go through the url pipes in angular 7+ or above

convert Indian rupees amount in words with paise

a = [
    '',
    'One ',
    'Two ',
    'Three ',
    'Four ',
    'Five ',
    'Six ',
    'Seven ',
    'Eight ',
    'Nine ',
    'Ten ',
    'Eleven ',
    'Twelve ',
    'Thirteen ',
    'Fourteen ',
    'Fifteen ',
    'Sixteen ',
    'Seventeen ',
    'Eighteen ',
    'Nineteen '];
b = [
    '',
    '',
    'Twenty',
    'Thirty',
    'Forty',
    'Fifty',
    'Sixty',
    'Seventy',
    'Eighty',
    'Ninety'];

transform(value: any): any {
    if (value) {
        let number = parseFloat(value).toFixed(2).split(".")
        let num = parseInt(number[0]);
        let digit = parseInt(number[1]);
        if (num) {
            if ((num.toString()).length > 9)  { return ''; }
            const n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            const d = ('00' + digit).substr(-2).match(/^(\d{2})$/);
            if (!n) {return ''; }
            let str = '';
            str += (Number(n[1]) !== 0) ? (this.a[Number(n[1])] || this.b[n[1][0]] + ' ' + this.a[n[1][1]]) + 'Crore ' : '';
            str += (Number(n[2]) !== 0) ? (this.a[Number(n[2])] || this.b[n[2][0]] + ' ' + this.a[n[2][1]]) + 'Lakh ' : '';
            str += (Number(n[3]) !== 0) ? (this.a[Number(n[3])] || this.b[n[3][0]] + ' ' + this.a[n[3][1]]) + 'Thousand ' : '';
            str += (Number(n[4]) !== 0) ? (this.a[Number(n[4])] || this.b[n[4][0]] + ' ' + this.a[n[4][1]]) + 'Hundred ' : '';
            str += (Number(n[5]) !== 0) ? (this.a[Number(n[5])] || this.b[n[5][0]] + ' ' + this.a[n[5][1]]) + 'Rupee ' : '';        
            str += (Number(d[1]) !== 0) ? ((str !== '' ) ? "and " : '') + (this.a[Number(d[1])] || this.b[d[1][0]] + ' ' + this.a[d[1][1]]) + 'Paise Only' : 'Only';
            return str;
        } else {
            return '';
        }
    } else {
        return '';
    }
}
Freezedrying answered 5/8, 2020 at 12:43 Comment(2)
could you add some explanation for your code, so the people can understand, what your code is doing?Banksia
I hope it's fine.Freezedrying

© 2022 - 2024 — McMap. All rights reserved.