Skip to content

Commit

Permalink
This "fixes" a bug in the Checkize function... but I don't trust the …
Browse files Browse the repository at this point in the history
…function anymore. This library needs unit tests.
  • Loading branch information
Giuseppe Burtini committed Jun 8, 2016
1 parent 28ea7ad commit b4e1f1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
require_once "src/HumanizePHP.php";
use gburtini\HumanizePHP;
require_once "src/gburtini/HumanizePHP/HumanizePHP.php";

use gburtini\HumanizePHP\HumanizePHP;
for($i=0;$i<100;$i++) {
echo HumanizePHP::ordinal($i) . "\t" . HumanizePHP::apnumber($i) . "\t" . HumanizePHP::intword($i*22000000) . "\n";
}
Expand All @@ -12,6 +13,8 @@
echo HumanizePHP::naturalday(strtotime("-3 weeks")) . "\n";

echo HumanizePHP::checkize(144) . "\n";

echo HumanizePHP::checkize(100) . "\n";
echo HumanizePHP::checkize(198234) . "\n";
echo HumanizePHP::checkize(9999999999) . "\n";
echo HumanizePHP::checkize(198) . "\n";
Expand Down
11 changes: 7 additions & 4 deletions src/gburtini/HumanizePHP/HumanizePHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,17 @@ static function checkize($number) {
if($specialCheck <= 19 && $specialCheck >= 10) {
$parts[] = $ten_singles[$number[strlen($number)-1]];
} else {
$parts[] = $singles[$number[strlen($number)-1]];
if($number > 10) {
$parts[] = $tens[$number[strlen($number)-2]] . " -";
$single = $number[strlen($number)-1];
if($single != 0 || $number < 10)
$parts[] = $singles[$single];

if($number > 10 && $number < 100) {
$parts[] = $tens[ $number[strlen($number)-2] ] . " -";
}
}

// special hundreds case (not a multiple of 3).
if($number > pow(10, 2)) {
if($number >= pow(10, 2)) {
$hundredsCount = $number[strlen($number)-3];
if($hundredsCount != 0) {
$parts[] = $singles[$hundredsCount] . " hundred";
Expand Down

0 comments on commit b4e1f1c

Please sign in to comment.