Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Amount into words

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);
console.log(inWords(1200))
Comment

PREVIOUS NEXT
Code Example
Javascript :: for loop js Alternatives 
Javascript :: why is this undefined in react 
Javascript :: read string using stream nodejs 
Javascript :: call local function javascript 
Javascript :: react native add react native vector icons not working 
Javascript :: console log on html 
Javascript :: js what does var mean 
Javascript :: Button get specific input hidden value JQuery 
Javascript :: express formidable 
Javascript :: get dynamic value in jquery 
Javascript :: download file using javascript 
Javascript :: Finding Value of Promise With Then Syntax 
Javascript :: react moment calendar times 
Javascript :: javascript this Inside Object Method 
Javascript :: javascript open method 
Javascript :: empty javascript 
Javascript :: javascript struct 
Javascript :: location maps react native 
Javascript :: upload file angular rest api 
Javascript :: jquery traversing methods 
Javascript :: firebase get subcollection 
Javascript :: javascript frames 
Javascript :: js value to boolean 
Javascript :: utc clock 
Javascript :: adding more than one class react 
Javascript :: byte array to json 
Javascript :: sequelize attributes exclude all 
Javascript :: return value 
Javascript :: javascript promise async 
Javascript :: datepicker range npm reactjs 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =