Skip to content

Instantly share code, notes, and snippets.

@anujgakhar
anujgakhar / num2words.coffee
Created February 23, 2014 08:55
A script that converts numbers to english words
class @NumberToWords
ones = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
tens = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
scales = ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion"]
convert: (num) ->
number = Math.abs(num)
return @check_negative(num, @convert_less_than_hundred number) if number < 100
return @check_negative(num, @convert_less_than_thousand number) if number < 1000
for n in [0..scales.length]
define([
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/on",
"dojo/dom-construct",
"dojo/dom-style",
'dijit/form/SimpleTextarea',
"dijit/_WidgetBase"
], function (
declare,