Thanks for replys:....I actually wrote it out myself before I looked at any links. Takes care of any number under 1000, which is all I needed.
Here it is in case anyone wants it: Im sure its not coded in the best way but it works fine. Just pass any number under 1000 into changeNumber and it will return the textual representation.
function changeNumber($number)
{
$numberArray = explode(".",$number);
$number_F = trim($numberArray[0]);
$number_D = trim($numberArray[1]);
$firstDigit = substr($number_F,0,1);
if (!$number_D) $number_D ="00";
if ($number_D < 10 && $number_D >= 1) $number_D = $number_D."0";
$textNumber = "";
if ($number_F > 99)
{
if ($firstDigit == 1) $textNumber = "One Hundred";
if ($firstDigit == 2) $textNumber = "Two Hundred";
if ($firstDigit == 3) $textNumber = "Three Hundred";
if ($firstDigit == 4) $textNumber = "Four Hundred";
if ($firstDigit == 5) $textNumber = "Five Hundred";
if ($firstDigit == 6) $textNumber = "Six Hundred";
if ($firstDigit == 7) $textNumber = "Seven Hundred";
if ($firstDigit == 8) $textNumber = "Eight Hundred";
if ($firstDigit == 9) $textNumber = "Nine Hundred";
$lastDigits = substr($number_F,1,2);
$lastDigitsString = change2DigitNumber($lastDigits);
$textNumber = "$textNumber $lastDigitsString and $number_D/100";
return $textNumber;
}
if ($number_F < 100 && $number_F>9)
{
$twoDigitString = change2DigitNumber($number_F);
$textNumber = "$twoDigitString and $number_D/100";
return $textNumber;
}
if ($number_F < 10)
{
if ($number_F == 1) $textNumber = "One";
if ($number_F == 2) $textNumber = "Two";
if ($number_F == 3) $textNumber = "Three";
if ($number_F == 4) $textNumber = "Four";
if ($number_F == 5) $textNumber = "Five";
if ($number_F == 6) $textNumber = "Six";
if ($number_F == 7) $textNumber = "Seven";
if ($number_F == 8) $textNumber = "Eight";
if ($number_F == 9) $textNumber = "Nine";
$textNumber = "$number_F and $number_D/100";
return $textNumber;
}
}
function change2DigitNumber($number)
{
$firstDigit = substr($number,0,1);
$secondDigit = substr($number,1,1);
$textNumber="";
if (!$firstDigit) return $textNumber;
//deal with the teens
if ($firstDigit == 1)
{
if (!$secondDigit) $textNumber="Ten";
if ($secondDigit == 1) $textNumber="Eleven";
if ($secondDigit == 2) $textNumber="Twelve";
if ($secondDigit == 3) $textNumber="Thirteen";
if ($secondDigit == 4) $textNumber="Fourteen";
if ($secondDigit == 5) $textNumber="Fifteen";
if ($secondDigit == 6) $textNumber="Sixteen";
if ($secondDigit == 7) $textNumber="Seventeen";
if ($secondDigit == 8) $textNumber="Eighteen";
if ($secondDigit == 9) $textNumber="Nineteen";
return $textNumber;
}
if ($firstDigit == 2)
{
if (!$secondDigit) $textNumber="Twenty";
if ($secondDigit == 1) $textNumber="Twenty-One";
if ($secondDigit == 2) $textNumber="Twenty-Two";
if ($secondDigit == 3) $textNumber="Twenty-Three";
if ($secondDigit == 4) $textNumber="Twenty-Four";
if ($secondDigit == 5) $textNumber="Twenty-Five";
if ($secondDigit == 6) $textNumber="Twenty-Six";
if ($secondDigit == 7) $textNumber="Twenty-Seven";
if ($secondDigit == 8) $textNumber="Twenty-Eight";
if ($secondDigit == 9) $textNumber="Twenty-Nine";
return $textNumber;
}
if ($firstDigit == 3)
{
if (!$secondDigit) $textNumber="Thirty";
if ($secondDigit == 1) $textNumber="Thirty-One";
if ($secondDigit == 2) $textNumber="Thirty-Two";
if ($secondDigit == 3) $textNumber="Thirty-Three";
if ($secondDigit == 4) $textNumber="Thirty-Four";
if ($secondDigit == 5) $textNumber="Thirty-Five";
if ($secondDigit == 6) $textNumber="Thirty-Six";
if ($secondDigit == 7) $textNumber="Thirty-Seven";
if ($secondDigit == 8) $textNumber="Thirty-Eight";
if ($secondDigit == 9) $textNumber="Thirty-Nine";
return $textNumber;
}
if ($firstDigit == 4)
{
if (!$secondDigit) $textNumber="Forty";
if ($secondDigit == 1) $textNumber="Forty-One";
if ($secondDigit == 2) $textNumber="Forty-Two";
if ($secondDigit == 3) $textNumber="Forty-Three";
if ($secondDigit == 4) $textNumber="Forty-Four";
if ($secondDigit == 5) $textNumber="Forty-Five";
if ($secondDigit == 6) $textNumber="Forty-Six";
if ($secondDigit == 7) $textNumber="Forty-Seven";
if ($secondDigit == 8) $textNumber="Forty-Eight";
if ($secondDigit == 9) $textNumber="Forty-Nine";
return $textNumber;
}
if ($firstDigit == 5)
{
if (!$secondDigit) $textNumber="Fifty";
if ($secondDigit == 1) $textNumber="Fifty-One";
if ($secondDigit == 2) $textNumber="Fifty-Two";
if ($secondDigit == 3) $textNumber="Fifty-Three";
if ($secondDigit == 4) $textNumber="Fifty-Four";
if ($secondDigit == 5) $textNumber="Fifty-Five";
if ($secondDigit == 6) $textNumber="Fifty-Six";
if ($secondDigit == 7) $textNumber="Fifty-Seven";
if ($secondDigit == 8) $textNumber="Fifty-Eight";
if ($secondDigit == 9) $textNumber="Fifty-Nine";
return $textNumber;
}
if ($firstDigit == 6)
{
if (!$secondDigit) $textNumber="Sixty";
if ($secondDigit == 1) $textNumber="Sixty-One";
if ($secondDigit == 2) $textNumber="Sixty-Two";
if ($secondDigit == 3) $textNumber="Sixty-Three";
if ($secondDigit == 4) $textNumber="Sixty-Four";
if ($secondDigit == 5) $textNumber="Sixty-Five";
if ($secondDigit == 6) $textNumber="Sixty-Six";
if ($secondDigit == 7) $textNumber="Sixty-Seven";
if ($secondDigit == 8) $textNumber="Sixty-Eight";
if ($secondDigit == 9) $textNumber="Sixty-Nine";
return $textNumber;
}
if ($firstDigit == 7)
{
if (!$secondDigit) $textNumber="Seventy";
if ($secondDigit == 1) $textNumber="Seventy-One";
if ($secondDigit == 2) $textNumber="Seventy-Two";
if ($secondDigit == 3) $textNumber="Seventy-Three";
if ($secondDigit == 4) $textNumber="Seventy-Four";
if ($secondDigit == 5) $textNumber="Seventy-Five";
if ($secondDigit == 6) $textNumber="Seventy-Six";
if ($secondDigit == 7) $textNumber="Seventy-Seven";
if ($secondDigit == 8) $textNumber="Seventy-Eight";
if ($secondDigit == 9) $textNumber="Seventy-Nine";
return $textNumber;
}
if ($firstDigit == 8)
{
if (!$secondDigit) $textNumber="Eighty";
if ($secondDigit == 1) $textNumber="Eighty-One";
if ($secondDigit == 2) $textNumber="Eighty-Two";
if ($secondDigit == 3) $textNumber="Eighty-Three";
if ($secondDigit == 4) $textNumber="Eighty-Four";
if ($secondDigit == 5) $textNumber="Eighty-Five";
if ($secondDigit == 6) $textNumber="Eighty-Six";
if ($secondDigit == 7) $textNumber="Eighty-Seven";
if ($secondDigit == 8) $textNumber="Eighty-Eight";
if ($secondDigit == 9) $textNumber="Eighty-Nine";
return $textNumber;
}
if ($firstDigit == 9)
{
if (!$secondDigit) $textNumber="Ninety";
if ($secondDigit == 1) $textNumber="Ninety-One";
if ($secondDigit == 2) $textNumber="Ninety-Two";
if ($secondDigit == 3) $textNumber="Ninety-Three";
if ($secondDigit == 4) $textNumber="Ninety-Four";
if ($secondDigit == 5) $textNumber="Ninety-Five";
if ($secondDigit == 6) $textNumber="Ninety-Six";
if ($secondDigit == 7) $textNumber="Ninety-Seven";
if ($secondDigit == 8) $textNumber="Ninety-Eight";
if ($secondDigit == 9) $textNumber="Ninety-Nine";
return $textNumber;
}
}