Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to convert entered number into currency in words in javascript

var a = ['','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ','thirteen ','fourteen ','fifteen ','sixteen ','seventeen ','eighteen ','nineteen '];
var b = ['', '', 'twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];

function inWords (num) {
    if ((num = num.toString()).length > 9) return 'overflow';
    n = ('000000000' + num).substr(-9).match(/^(d{2})(d{2})(d{2})(d{1})(d{2})$/);
    if (!n) return; var str = '';
    str += (n[1] != 0) ? (a[Number(n[1])] || b[n[1][0]] + ' ' + a[n[1][1]]) + 'crore ' : '';
    str += (n[2] != 0) ? (a[Number(n[2])] || b[n[2][0]] + ' ' + a[n[2][1]]) + 'lakh ' : '';
    str += (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'thousand ' : '';
    str += (n[4] != 0) ? (a[Number(n[4])] || b[n[4][0]] + ' ' + a[n[4][1]]) + 'hundred ' : '';
    str += (n[5] != 0) ? ((str != '') ? 'and ' : '') + (a[Number(n[5])] || b[n[5][0]] + ' ' + a[n[5][1]]) + 'only ' : '';
    return str;
}

document.getElementById('number').onkeyup = function () {
    document.getElementById('words').innerHTML = inWords(document.getElementById('number').value);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: call javascript function use array 
Javascript :: angular {{}} new line 
Javascript :: remove duplicate items from array 
Javascript :: javascript click coordinates on page 
Javascript :: javascript change background color 
Javascript :: This is the RegEx for Roman numerals 
Javascript :: javascript base 10 to base 2 
Javascript :: javascrip check if string contains substring 
Javascript :: webpack bundle analyzer 
Javascript :: Could not find the drag and drop manager in the context of ResourceEvents. Make sure to wrap the top-level component of your app with DragDropContext 
Javascript :: install node on ubuntu and debian 
Javascript :: Loop array backwards in JS 
Javascript :: get offset from timezone javascript 
Javascript :: local string method 
Javascript :: moment cdn 
Javascript :: append element in a div as first child 
Javascript :: chartjs line color 
Javascript :: find one with specofoc id mongoose 
Javascript :: remove symbols from cpf js 
Javascript :: get element by click 
Javascript :: jquery replace html 
Javascript :: how to uncheck a radio button 
Javascript :: react native android padding style 
Javascript :: ajax done 
Javascript :: vue dynamic route push with params 
Javascript :: dangerouslySetInnerHTML 
Javascript :: iiee i 
Javascript :: javascript WeakSet Methods 
Javascript :: javascript array push element at index 
Javascript :: miles to metres js 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =