showing results for - "javascript amount in words"
Niclas
30 Sep 2019
1var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ','thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen '];
2var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
3
4function inWords (num) {
5    if ((num = num.toString()).length > 9) return 'overflow';
6    n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
7    if (!n) return; var str = '';
8    str += (n[1] != 0) ? (a[Number(n[1])] || b[n[1][0]] + ' ' + a[n[1][1]]) + 'crore ' : '';
9    str += (n[2] != 0) ? (a[Number(n[2])] || b[n[2][0]] + ' ' + a[n[2][1]]) + 'lakh ' : '';
10    str += (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'thousand ' : '';
11    str += (n[4] != 0) ? (a[Number(n[4])] || b[n[4][0]] + ' ' + a[n[4][1]]) + 'hundred ' : '';
12    str += (n[5] != 0) ? ((str != '') ? 'and ' : '') + (a[Number(n[5])] || b[n[5][0]] + ' ' + a[n[5][1]]) + 'only ' : '';
13    return str;
14}
15
16document.getElementById('number').onkeyup = function () {
17    document.getElementById('words').innerHTML = inWords(document.getElementById('number').value);
18};
queries leading to this page
number to word javascriptconvert number to currency in javascripthow to convert entered number into currency in words in javascriptjavascript convert number to wordswords to number in reactshow specific number of words javascriptjavascript to get number in wordscurrency to words javascriptjavascript digit to wordnumber to word converter javascript codeamount in words dollar in javascriptamount to words javascriptamount in words javascriptconvert number to words javascriptamount in indian words javascriptdisplay number in words in javascriptconvert numeric value into words 28currency 29 in jsjavascript currency to numberamount to word currency javascriptconvert indian currency numbers to words in javascriptconvert number to words in javascriptnumber in words jsjavascript currency format to numbernumber to words indian currency javascriptjavascript convert number to currencynumber of words javascriptconvert amount in words javascriptnumber to words javascripthow to convert number to currency in javascriptjavascript convert amount to wordsjavascript code to convert numeric numbers into wordscurrency to words jsjavascript single digit to word javascript to convert number to currencyextract number out of currency string javascriptjavascript function convert number to currencyjs number to words currencyjavascript phone numbers to wordsnumber to word jsjs currency to wordsnumbers to words converter using jsjavascript number o wordsjavascript amount in words