Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert number to word js

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 :: google maps places autocomplete api 
Javascript :: javascript create array of objects from multiple arrays 
Javascript :: how to print a line in javascript 
Javascript :: how to change text color in react 
Javascript :: json-server npm 
Javascript :: stomp.min.js cdn 
Javascript :: how to find length of a assocative array vuejs 
Javascript :: convert string number with commas decimal to number javascript 
Javascript :: iterate over map in javascript 
Javascript :: discord.js get first mention 
Javascript :: add click event listener javascript 
Javascript :: javascript calculate time 
Javascript :: programatic navigation vue router 
Javascript :: jquery datatable get column values in array 
Javascript :: toggle state react 
Javascript :: javascript toPrecision() Method 
Javascript :: how to make one line if in js 
Javascript :: reduce array to object javascript 
Javascript :: javascript console.log alternative 
Javascript :: js sleep 
Javascript :: chai compare arrays 
Javascript :: javascript download current html page 
Javascript :: stripe react js 
Javascript :: react-data-table-component api action button 
Javascript :: jquery navigation 
Javascript :: onclick change image src javascript 
Javascript :: hover con js 
Javascript :: count json objects 
Javascript :: react public pic 
Javascript :: onclick function jquery 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =