diff --git a/code b/code new file mode 100644 index 0000000..226314b --- /dev/null +++ b/code @@ -0,0 +1,211 @@ + 0) + { + $output .= " point"; + for ($i = 0; $i < strlen($fraction); $i++) + { + $output .= " " . GetSingleDigit($fraction{$i}); + } + } + return $output; +} + +function GetThreeMore($index) +{ + switch ($index) + { + case 2: + return " million"; + case 1: + return " thousand"; + case 0: + return ""; + } +} + +function GetThreeDigit($digit1, $digit2, $digit3) +{ + $buffer = ""; + + if ($digit1 == "0" && $digit2 == "0" && $digit3 == "0") + { + return ""; + } + + if ($digit1 != "0") + { + $buffer .= GetSingleDigit($digit1) . " hundred"; + if ($digit2 != "0" || $digit3 != "0") + { + $buffer .= " "; + } + } + + if ($digit2 != "0") + { + $buffer .= GetTwoDigit($digit2, $digit3); + } + else if ($digit3 != "0") + { + $buffer .= GetSingleDigit($digit3); + } + + return $buffer; +} + +function GetTwoDigit($digit1, $digit2) +{ + if ($digit2 == "0") + { + switch ($digit1) + { + case "1": + return "Ten"; + case "2": + return "Twenty"; + case "3": + return "Thirty"; + case "4": + return "Forty"; + case "5": + return "Fifty"; + case "6": + return "Sixty"; + case "7": + return "Seventy"; + case "8": + return "Eighty"; + case "9": + return "Ninety"; + } + } else if ($digit1 == "1") + { + switch ($digit2) + { + case "1": + return "Eleven"; + case "2": + return "Twelve"; + case "3": + return "Thirteen"; + case "4": + return "Fourteen"; + case "5": + return "Fifteen"; + case "6": + return "Sixteen"; + case "7": + return "Seventeen"; + case "8": + return "Eighteen"; + case "9": + return "Nineteen"; + } + } else + { + $number = GetSingleDigit($digit2); + switch ($digit1) + { + case "2": + return "Twenty $number"; + case "3": + return "Thirty $number"; + case "4": + return "Forty $number"; + case "5": + return "Fifty $number"; + case "6": + return "Sixty $number"; + case "7": + return "Seventy $number"; + case "8": + return "Eighty $number"; + case "9": + return "Ninety $number"; + } + } +} + +function GetSingleDigit($digit) +{ + switch ($digit) + { + case "0": + return "Zero"; + case "1": + return "One"; + case "2": + return "Two"; + case "3": + return "Three"; + case "4": + return "Four"; + case "5": + return "Five"; + case "6": + return "Six"; + case "7": + return "Seven"; + case "8": + return "Eight"; + case "9": + return "Nine"; + } +} + +echo(convertNumber($number)); + +?>