Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert number to word js crore/lakh format

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 :: set js 
Javascript :: change index array javascript 
Javascript :: index of value in array 
Javascript :: detect a click outside an element javascript 
Javascript :: merge 2 dictionaries with same keys javascript 
Javascript :: currying javascript sum 
Javascript :: find max days of month js 
Javascript :: javascript, digit thousand formatting, number formating js, regexp, number comma seperation js 
Javascript :: javascript remove innerhtml 
Javascript :: if checkbox checked jquery value 1 
Javascript :: datatables filter with math functions 
Javascript :: how to push string into array in javascript 
Javascript :: add params to url vue 
Javascript :: scrapy javascript 
Javascript :: add id attribute to jQuery steps 
Javascript :: discord.js edit message by id 
Javascript :: how to slice/trim/remove last character in string 
Javascript :: creating array of objects usinng reduce js 
Javascript :: why is my req.body empty 
Javascript :: foreach loop javascript 
Javascript :: react js get screen size 
Javascript :: sleeping in js 
Javascript :: javascript find object in array 
Javascript :: moment time format by country 
Javascript :: slide out navigation 
Javascript :: onclick change image javascript example 
Javascript :: cannot use import statement outside a module 
Javascript :: check if two rectangles overlap javascript canvas 
Javascript :: validate password with 8 Characters, One Uppercase, One Lowercase, One Number and One Special Case Character 
Javascript :: convert arraybuffer to file javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =