[ create a new paste ] login | about

Link: http://codepad.org/GUr1pDCV    [ raw code | output | fork ]

PHP, pasted on Jan 21:
<?php

function N2L($number)
{
	$result = array();
	$tens = floor($number / 10);
	$units = $number % 10;

	$words = array
	(
		'units' => array('', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eightteen', 'Nineteen'),
		'tens' => array('', '', 'Twenty', 'Thirty', 'Fourty', 'Fifty', 'Sixty', 'Seventy', 'Eigthy', 'Ninety')
	);

	if ($tens < 2)
	{
		$result[] = $words['units'][$tens * 10 + $units];
	}

	else
	{
		$result[] = $words['tens'][$tens];

		if ($units > 0)
		{
			$result[count($result) - 1] .= '-' . $words['units'][$units];
		}
	}

	if (empty($result[0]))
	{
		$result[0] = 'Zero';
	}

	return trim(implode(' ', $result));
}

for ($i = 0; $i <= 99; $i++)
{
	echo strtolower(N2L($i)) . "\n";
}

?>


Output:
zero
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eightteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
fourty
fourty-one
fourty-two
fourty-three
fourty-four
fourty-five
fourty-six
fourty-seven
fourty-eight
fourty-nine
fifty
fifty-one
fifty-two
fifty-three
fifty-four
fifty-five
fifty-six
fifty-seven
fifty-eight
fifty-nine
sixty
sixty-one
sixty-two
sixty-three
sixty-four
sixty-five
sixty-six
sixty-seven
sixty-eight
sixty-nine
seventy
seventy-one
seventy-two
seventy-three
seventy-four
seventy-five
seventy-six
seventy-seven
seventy-eight
seventy-nine
eigthy
eigthy-one
eigthy-two
eigthy-three
eigthy-four
eigthy-five
eigthy-six
eigthy-seven
eigthy-eight
eigthy-nine
ninety
ninety-one
ninety-two
ninety-three
ninety-four
ninety-five
ninety-six
ninety-seven
ninety-eight
ninety-nine


Create a new paste based on this one


Comments: