classes/English.js
function() {
		var n = this;
		if (n<20) {
			return [
				'zero', 'one', 'two', 'three', 'four', 'five',
				'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
				'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
				'seventeen', 'eighteen', 'nineteen' ][n];
		} else if (n<100) {
			var tens = Math.floor(n/10);
			var ones = n%10;
			return [
				'twenty', 'thirty', 'forty', 'fifty', 'sixty',
				'seventy', 'eighty', 'ninety'
			][tens-2]+((ones>0) ? '-'+ones.toWord() : '');
		} else if (n<1000) {
			var hundreds = Math.floor(n/100);
			var tens = n%100;
			return hundreds.toWord()+' hundred and '+tens.toWord();
		}

		var places = ['thousand', 'million', 'billion', 'trillion'];
		var d   = Math.floor(new String(n).length/3);
		var pow = Math.pow(1000, d);
		var principle = Math.floor(n/pow);
		var remainder = n%pow;
		return principle.toWord()+' '+places[d-1]+' '+remainder.toWord();
	}
function() {
		var n = this;
		if (n<20) {
			return [
				'zero', 'one', 'two', 'three', 'four', 'five',
				'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
				'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
				'seventeen', 'eighteen', 'nineteen' ][n];
		} else if (n<100) {
			var tens = Math.floor(n/10);
			var ones = n%10;
			return [
				'twenty', 'thirty', 'forty', 'fifty', 'sixty',
				'seventy', 'eighty', 'ninety'
			][tens-2]+((ones>0) ? '-'+ones.toWord() : '');
		} else if (n<1000) {
			var hundreds = Math.floor(n/100);
			var tens = n%100;
			return hundreds.toWord()+' hundred and '+tens.toWord();
		}

		var places = ['thousand', 'million', 'billion', 'trillion'];
		var d   = Math.floor(new String(n).length/3);
		var pow = Math.pow(1000, d);
		var principle = Math.floor(n/pow);
		var remainder = n%pow;
		return principle.toWord()+' '+places[d-1]+' '+remainder.toWord();
	}
function ( ) { var n = this ; if ( n < 20 ) { return [ 'zero' , 'one' , 'two' , 'three' , 'four' , 'five' , 'six' , 'seven' , 'eight' , 'nine' , 'ten' , 'eleven' , 'twelve' , 'thirteen' , 'fourteen' , 'fifteen' , 'sixteen' , 'seventeen' , 'eighteen' , 'nineteen' ] [ n ] ; } else if ( n < 100 ) { var tens = Math . floor ( n / 10 ) ; var ones = n % 10 ; return [ 'twenty' , 'thirty' , 'forty' , 'fifty' , 'sixty' , 'seventy' , 'eighty' , 'ninety' ] [ tens - 2 ] + ( ( ones > 0 ) ? '-' + ones . toWord ( ) : '' ) ; } else if ( n < 1000 ) { var hundreds = Math . floor ( n / 100 ) ; var tens = n % 100 ; return hundreds . toWord ( ) + ' hundred and ' + tens . toWord ( ) ; } var places = [ 'thousand' , 'million' , 'billion' , 'trillion' ] ; var d = Math . floor ( new String ( n ) . length / 3 ) ; var pow = Math . pow ( 1000 , d ) ; var principle = Math . floor ( n / pow ) ; var remainder = n % pow ; return principle . toWord ( ) + ' ' + places [ d - 1 ] + ' ' + remainder . toWord ( ) ; }
Converts a number up to whatever comes after the trillions into English.
Converts a number up to whatever comes after the trillions into English .