<?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);
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