function test_NumberToWord_thousands_tens() { //arrange $test_NumberValues = new NumberToWord(); $input = "123456789"; //act $result = $test_NumberValues->getWord($input); //assert $this->assertEquals(" one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine ", $result); }
*/ $errorMessage = array("NOT_NUMBER" => "The string entered is not a number.\n", "OUT_OF_RANGE" => "This code only accepts numbers between -" . PHP_INT_MAX . " and " . PHP_INT_MAX . ".\n"); /** * Start the script */ echo "Please enter a number to convert to word: \n"; /** * Get the input from command line */ $handle = fopen("php://stdin", "r"); $line = fgets($handle); $number = trim($line); /** * initial the class */ $converter = new NumberToWord($number); /** * get the result */ $result = $converter->convert($number); /** * error handling */ if ($result === false) { echo $errorMessage[$converter->getErrorMessage()] . "\n"; exit; } /** * echo out the word if no error */ echo $result . "\n";
<?php require 'NumberToWord.php'; $ntw = new NumberToWord(12123220.51); echo $ntw->show();
$strWord = $this->arrNumbers[$plainNumber]; } else { $strWord = $this->double($number1, true, $this->single($number2, $this->inDec($number1, $number2), true)); } if ($number2 != 0) { unset($this->arrWord[0]); } array_unshift($this->arrWord, $strWord . $this->arrNumbers['-000']); } function hundredthousand($number1, $number2, $number3) { if ($number1 == 0) { return; } array_unshift($this->arrWord, $this->hundred($number1, true) . ($number2 == 0 ? $this->arrNumbers['-000'] : '')); } } /** * Use */ //$n2w = new NumberToWord; //$n2w->setNumber(999999); //echo $n2w->getWord(); $n2w = new NumberToWord(); //echo '<pre>'; for ($i = 1; $i <= 10000; $i++) { $n2w->setNumber($i); //echo $n2w->getWord() . '<br />'; echo $n2w->getWord() . "\n"; } //echo '</pre>';
/** * test a larger number */ public function testOneMillion() { $obj = new NumberToWord(); $this->assertTrue($obj->convert("1000000") == "one million"); }