Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert number to word crore/lakhs

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

function inWords(num) {
  if ((num = num.toString()).length > 9) return "overflow";
  let 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;
}

/* eslint eqeqeq: 0 */
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert number to word j 
Javascript :: set label text in jquery 
Javascript :: nodejs fs root folder path 
Javascript :: react native modal not full screen 
Javascript :: jquery select input with class 
Javascript :: javascript check if variable is a jquery object 
Javascript :: how to delete a reply in discord.js 
Javascript :: how to generate random id in javascript 
Javascript :: What is the syntax to export a function from a module in Node.js 
Javascript :: js number format 
Javascript :: localstorage clear item 
Javascript :: axios network error react native 
Javascript :: eslint ignorel ine 
Javascript :: how to fill array with consecutive numbers javascript 
Javascript :: apply eventlistener to iframe 
Javascript :: Check If Something Is An Array or Not 
Javascript :: javascript check image src 
Javascript :: firebase for vue project 
Javascript :: check local storage javascript 
Javascript :: jquery add div 
Javascript :: react hook form with yup resolver 
Javascript :: process env react undefined 
Javascript :: js addeventlistener arrow keys 
Javascript :: javascript pass parameter to event listener 
Javascript :: mongodb aggregate node.js 
Javascript :: js ternary 
Javascript :: flask return status code 200 and json 
Javascript :: javascript array move element one position 
Javascript :: javascript dir 
Javascript :: foreach jas 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =