|
|
|
|
|
|
| |
| <?php
/***********************************************
* Example Name : Num2Words *
* Scripted By : Glen Mc Arthur *
* Email : glen.mcarthur@gmail.com *
* License : GPL (Gnu Public License) *
***********************************************/
// START CONVERTION CLASS
class num2words {
var $numb = Array();
var $tail;
var $number;
var $currency;
var $min;
function num2words () {
$this->numb = Array ("",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine");
}
function mod($a,$b) {
return $a-$b*floor($a/$b);
}
function setTail($str) {
$this->tail = $str;
}
function setNumber($int) {
$int = trim($int);
if (is_int(strpos($int,"-"))) {
$this->number = substr($int,strpos($int,"-")+1,strlen($int));
$this->currency = "minus";
} else {
$this->number = $int;
}
$this->setAsCurrency();
}
function getCurrency() {
return $this->currency;
}
function printCurrency() {
print ucfirst(strtolower(trim($this->currency)));
}
function setAsCurrency() {
$xpos = strpos($this->number,".");
if (is_int($xpos)) {
$pecahan = round(substr($this->number,$xpos,strlen($this->number)),2);
$sisa = substr($this->number,0,$xpos);
} else {
$pecahan = "";
$sisa = $this->number;
}
if ($sisa==0 || $this->number==0) {
$this->currency .= "zero ".$this->tail;
} else {
$trilion = floor($sisa/pow(10,12));
$sisa = $this->mod($sisa,1000000000000);
$billion = floor($sisa/pow(10,9));
$sisa = $this->mod($sisa,1000000000);
$million = floor($sisa/pow(10,6));
$sisa = $this->mod($sisa,1000000);
$thousand = floor($sisa/pow(10,3));
$sisa = $this->mod($sisa,1000);
$words = $this->ThreeDigit($trilion, "trilion");
$words .= $this->ThreeDigit($billion, "billion");
$words .= $this->ThreeDigit($million, "million");
$words .= $this->ThreeDigit($thousand, "thousand");
$words .= $this->ThreeDigit($sisa,"");
$words .= " ".$this->tail;
}
if ($pecahan>0) {
$words .= " and". $this->ThreeDigit(round($pecahan*100),"sen");
}
$this->currency .= strtolower($words);
}
function ThreeDigit($amount, $suffix="") {
$sisa = (int) $amount;
$words = "";
if ($sisa < 20 && $sisa > 10) {
if ($sisa==11) {
$words = " eleven";
} elseif ($sisa == 12) {
$words = " twelve";
} elseif ($sisa == 13) {
$words = " thirteen";
} elseif ($sisa == 15) {
$words = " fifteen";
} elseif ($sisa == 18) {
$words = " eighteen";
} else {
$words = " ".$this->numb[$sisa-10]."teen";
}
if ($suffix != "") {
$words .= " ".$suffix;
}
return $words;
}
$ratus = floor($sisa/100);
if ($ratus <= 0) {
$words .= "";
} else {
$words .= " ".$this->numb[$ratus]." hundred";
}
$sisa = $this->mod($sisa,100);
if ($sisa < 20 && $sisa > 10) {
if ($sisa == 11) {
$words .= " eleven ". $suffix;
} elseif ($sisa == 12) {
$words .= " twelve";
} elseif ($sisa == 13) {
$words .= " thirteen";
} elseif ($sisa == 15) {
$words .= " fifteen";
} elseif ($sisa == 18) {
$words .= " eighteen";
} else {
$words .= " ".$this->numb[$sisa-10]."teen ". $suffix;
}
return $words;
}
$puluh = floor($sisa/10);
if ($puluh == 0) {
$words .= "";
} elseif ($puluh == 1) {
$words .= " ten";
} elseif ($puluh == 2) {
$words .= " twenty";
} elseif ($puluh == 3) {
$words .= " thirty";
} elseif ($puluh == 5) {
$words .= " fifty";
} elseif ($puluh == 5) {
$words .= " eighty";
} else {
$words .= " ".$this->numb[$puluh]."ty";
}
$sisa = $this->mod($sisa,10);
if ($sisa>0&&$sisa<=9) {
$words .= " ".$this->numb[$sisa];
}
if ($amount>0&&$amount<=1000) {
$words .= " ".$suffix;
}
return $words;
}
}
// END CONVERTION CLASS
?> | | |
|
| very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | A Timing Class Categories : PHP, PHP Classes, Date Time | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | These PHP Classes Check if a host is alive using various methods. Categories : PHP, PHP Classes, Sockets, CURL | | | an example of the cyberlib payment class Categories : PHP, PHP Classes, Ecommerce, Credit Cards | | | Power Form Validation Categories : PHP, PHP Classes, Data Validation | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | Browser Detecor Class Categories : PHP Classes, PHP, HTML | |
| | | | matthew waygood wrote :1362
As with most number as text functions this has been written for Americans. It would be nice to include the option to specify the rest of the world too.
ie 1,000,000 is one million
however 1,000,000,000 in the US is a billion, but to everyone else its just a thousand million.
1,000,000,000,000 is a trillion, and to everyone else a billion.
This works on BI meaning two, as in bicycle, so a billion is 2 lots of a million hense 12 (2x6) zeros.
Probably done by Webster who standardised English with an emphasis on Phonetics. eg. Colour/Color
| |
|
|
|