| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Numbers_Words
|
|
|
4 |
*
|
|
|
5 |
* PHP version 4
|
|
|
6 |
*
|
|
|
7 |
* Copyright (c) 1997-2006 The PHP Group
|
|
|
8 |
*
|
|
|
9 |
* This source file is subject to version 3.0 of the PHP license,
|
|
|
10 |
* that is bundled with this package in the file LICENSE, and is
|
|
|
11 |
* available at through the world-wide-web at
|
|
|
12 |
* http://www.php.net/license/3_0.txt.
|
|
|
13 |
* If you did not receive a copy of the PHP license and are unable to
|
|
|
14 |
* obtain it through the world-wide-web, please send a note to
|
|
|
15 |
* license@php.net so we can mail you a copy immediately.
|
|
|
16 |
*
|
|
|
17 |
* @category Numbers
|
|
|
18 |
* @package Numbers_Words
|
|
|
19 |
* @author Piotr Klaban <makler@man.torun.pl>
|
|
|
20 |
* @license PHP 3.0 http://www.php.net/license/3_0.txt
|
|
|
21 |
* @version CVS: $Id: lang.en_US.php 269648 2008-11-25 02:45:52Z clockwerx $
|
|
|
22 |
* @link http://pear.php.net/package/Numbers_Words
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Class for translating numbers into American English.
|
|
|
27 |
*
|
|
|
28 |
* @author Piotr Klaban
|
|
|
29 |
* @package Numbers_Words
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Include needed files
|
|
|
34 |
*/
|
|
|
35 |
require_once "Numbers/Words.php";
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Class for translating numbers into American English.
|
|
|
39 |
*
|
|
|
40 |
* @category Numbers
|
|
|
41 |
* @package Numbers_Words
|
|
|
42 |
* @author Piotr Klaban <makler@man.torun.pl>
|
|
|
43 |
* @license PHP 3.0 http://www.php.net/license/3_0.txt
|
|
|
44 |
* @link http://pear.php.net/package/Numbers_Words
|
|
|
45 |
*/
|
|
|
46 |
class Numbers_Words_en_US extends Numbers_Words
|
|
|
47 |
{
|
|
|
48 |
|
|
|
49 |
// {{{ properties
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Locale name
|
|
|
53 |
* @var string
|
|
|
54 |
* @access public
|
|
|
55 |
*/
|
|
|
56 |
var $locale = 'en_US';
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Language name in English
|
|
|
60 |
* @var string
|
|
|
61 |
* @access public
|
|
|
62 |
*/
|
|
|
63 |
var $lang = 'American English';
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Native language name
|
|
|
67 |
* @var string
|
|
|
68 |
* @access public
|
|
|
69 |
*/
|
|
|
70 |
var $lang_native = 'American English';
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* The word for the minus sign
|
|
|
74 |
* @var string
|
|
|
75 |
* @access private
|
|
|
76 |
*/
|
|
|
77 |
var $_minus = 'minus'; // minus sign
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* The sufixes for exponents (singular and plural)
|
|
|
81 |
* Names partly based on:
|
|
|
82 |
* http://home.earthlink.net/~mrob/pub/math/largenum.html
|
|
|
83 |
* http://mathforum.org/dr.math/faq/faq.large.numbers.html
|
|
|
84 |
* http://www.mazes.com/AmericanNumberingSystem.html
|
|
|
85 |
* @var array
|
|
|
86 |
* @access private
|
|
|
87 |
*/
|
|
|
88 |
var $_exponent = array(
|
|
|
89 |
|
|
|
90 |
3 => array('thousand'),
|
|
|
91 |
6 => array('million'),
|
|
|
92 |
9 => array('billion'),
|
|
|
93 |
12 => array('trillion'),
|
|
|
94 |
15 => array('quadrillion'),
|
|
|
95 |
18 => array('quintillion'),
|
|
|
96 |
21 => array('sextillion'),
|
|
|
97 |
24 => array('septillion'),
|
|
|
98 |
27 => array('octillion'),
|
|
|
99 |
30 => array('nonillion'),
|
|
|
100 |
33 => array('decillion'),
|
|
|
101 |
36 => array('undecillion'),
|
|
|
102 |
39 => array('duodecillion'),
|
|
|
103 |
42 => array('tredecillion'),
|
|
|
104 |
45 => array('quattuordecillion'),
|
|
|
105 |
48 => array('quindecillion'),
|
|
|
106 |
51 => array('sexdecillion'),
|
|
|
107 |
54 => array('septendecillion'),
|
|
|
108 |
57 => array('octodecillion'),
|
|
|
109 |
60 => array('novemdecillion'),
|
|
|
110 |
63 => array('vigintillion'),
|
|
|
111 |
66 => array('unvigintillion'),
|
|
|
112 |
69 => array('duovigintillion'),
|
|
|
113 |
72 => array('trevigintillion'),
|
|
|
114 |
75 => array('quattuorvigintillion'),
|
|
|
115 |
78 => array('quinvigintillion'),
|
|
|
116 |
81 => array('sexvigintillion'),
|
|
|
117 |
84 => array('septenvigintillion'),
|
|
|
118 |
87 => array('octovigintillion'),
|
|
|
119 |
90 => array('novemvigintillion'),
|
|
|
120 |
93 => array('trigintillion'),
|
|
|
121 |
96 => array('untrigintillion'),
|
|
|
122 |
99 => array('duotrigintillion'),
|
|
|
123 |
// 100 => array('googol') - not latin name
|
|
|
124 |
// 10^googol = 1 googolplex
|
|
|
125 |
102 => array('trestrigintillion'),
|
|
|
126 |
105 => array('quattuortrigintillion'),
|
|
|
127 |
108 => array('quintrigintillion'),
|
|
|
128 |
111 => array('sextrigintillion'),
|
|
|
129 |
114 => array('septentrigintillion'),
|
|
|
130 |
117 => array('octotrigintillion'),
|
|
|
131 |
120 => array('novemtrigintillion'),
|
|
|
132 |
123 => array('quadragintillion'),
|
|
|
133 |
126 => array('unquadragintillion'),
|
|
|
134 |
129 => array('duoquadragintillion'),
|
|
|
135 |
132 => array('trequadragintillion'),
|
|
|
136 |
135 => array('quattuorquadragintillion'),
|
|
|
137 |
138 => array('quinquadragintillion'),
|
|
|
138 |
141 => array('sexquadragintillion'),
|
|
|
139 |
144 => array('septenquadragintillion'),
|
|
|
140 |
147 => array('octoquadragintillion'),
|
|
|
141 |
150 => array('novemquadragintillion'),
|
|
|
142 |
153 => array('quinquagintillion'),
|
|
|
143 |
156 => array('unquinquagintillion'),
|
|
|
144 |
159 => array('duoquinquagintillion'),
|
|
|
145 |
162 => array('trequinquagintillion'),
|
|
|
146 |
165 => array('quattuorquinquagintillion'),
|
|
|
147 |
168 => array('quinquinquagintillion'),
|
|
|
148 |
171 => array('sexquinquagintillion'),
|
|
|
149 |
174 => array('septenquinquagintillion'),
|
|
|
150 |
177 => array('octoquinquagintillion'),
|
|
|
151 |
180 => array('novemquinquagintillion'),
|
|
|
152 |
183 => array('sexagintillion'),
|
|
|
153 |
186 => array('unsexagintillion'),
|
|
|
154 |
189 => array('duosexagintillion'),
|
|
|
155 |
192 => array('tresexagintillion'),
|
|
|
156 |
195 => array('quattuorsexagintillion'),
|
|
|
157 |
198 => array('quinsexagintillion'),
|
|
|
158 |
201 => array('sexsexagintillion'),
|
|
|
159 |
204 => array('septensexagintillion'),
|
|
|
160 |
207 => array('octosexagintillion'),
|
|
|
161 |
210 => array('novemsexagintillion'),
|
|
|
162 |
213 => array('septuagintillion'),
|
|
|
163 |
216 => array('unseptuagintillion'),
|
|
|
164 |
219 => array('duoseptuagintillion'),
|
|
|
165 |
222 => array('treseptuagintillion'),
|
|
|
166 |
225 => array('quattuorseptuagintillion'),
|
|
|
167 |
228 => array('quinseptuagintillion'),
|
|
|
168 |
231 => array('sexseptuagintillion'),
|
|
|
169 |
234 => array('septenseptuagintillion'),
|
|
|
170 |
237 => array('octoseptuagintillion'),
|
|
|
171 |
240 => array('novemseptuagintillion'),
|
|
|
172 |
243 => array('octogintillion'),
|
|
|
173 |
246 => array('unoctogintillion'),
|
|
|
174 |
249 => array('duooctogintillion'),
|
|
|
175 |
252 => array('treoctogintillion'),
|
|
|
176 |
255 => array('quattuoroctogintillion'),
|
|
|
177 |
258 => array('quinoctogintillion'),
|
|
|
178 |
261 => array('sexoctogintillion'),
|
|
|
179 |
264 => array('septoctogintillion'),
|
|
|
180 |
267 => array('octooctogintillion'),
|
|
|
181 |
270 => array('novemoctogintillion'),
|
|
|
182 |
273 => array('nonagintillion'),
|
|
|
183 |
276 => array('unnonagintillion'),
|
|
|
184 |
279 => array('duononagintillion'),
|
|
|
185 |
282 => array('trenonagintillion'),
|
|
|
186 |
285 => array('quattuornonagintillion'),
|
|
|
187 |
288 => array('quinnonagintillion'),
|
|
|
188 |
291 => array('sexnonagintillion'),
|
|
|
189 |
294 => array('septennonagintillion'),
|
|
|
190 |
297 => array('octononagintillion'),
|
|
|
191 |
300 => array('novemnonagintillion'),
|
|
|
192 |
303 => array('centillion'),
|
|
|
193 |
309 => array('duocentillion'),
|
|
|
194 |
312 => array('trecentillion'),
|
|
|
195 |
366 => array('primo-vigesimo-centillion'),
|
|
|
196 |
402 => array('trestrigintacentillion'),
|
|
|
197 |
603 => array('ducentillion'),
|
|
|
198 |
624 => array('septenducentillion'),
|
|
|
199 |
// bug on a earthlink page: 903 => array('trecentillion'),
|
|
|
200 |
2421 => array('sexoctingentillion'),
|
|
|
201 |
3003 => array('millillion'),
|
|
|
202 |
3000003 => array('milli-millillion')
|
|
|
203 |
);
|
|
|
204 |
|
|
|
205 |
/**
|
|
|
206 |
* The array containing the digits (indexed by the digits themselves).
|
|
|
207 |
* @var array
|
|
|
208 |
* @access private
|
|
|
209 |
*/
|
|
|
210 |
var $_digits = array(
|
|
|
211 |
|
|
|
212 |
'five', 'six', 'seven', 'eight', 'nine'
|
|
|
213 |
);
|
|
|
214 |
|
|
|
215 |
/**
|
|
|
216 |
* The word separator
|
|
|
217 |
* @var string
|
|
|
218 |
* @access private
|
|
|
219 |
*/
|
|
|
220 |
var $_sep = ' ';
|
|
|
221 |
|
|
|
222 |
/**
|
|
|
223 |
* The currency names (based on the below links,
|
|
|
224 |
* informations from central bank websites and on encyclopedias)
|
|
|
225 |
*
|
|
|
226 |
* @var array
|
|
|
227 |
* @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
|
|
|
228 |
* @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
|
|
|
229 |
* @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
|
|
|
230 |
* @access private
|
|
|
231 |
*/
|
|
|
232 |
var $_currency_names = array(
|
|
|
233 |
'ALL' => array(array('lek'), array('qindarka')),
|
|
|
234 |
'AUD' => array(array('Australian dollar'), array('cent')),
|
|
|
235 |
'BAM' => array(array('convertible marka'), array('fenig')),
|
|
|
236 |
'BGN' => array(array('lev'), array('stotinka')),
|
|
|
237 |
'BRL' => array(array('real'), array('centavos')),
|
|
|
238 |
'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
|
|
|
239 |
'CAD' => array(array('Canadian dollar'), array('cent')),
|
|
|
240 |
'CHF' => array(array('Swiss franc'), array('rapp')),
|
|
|
241 |
'CYP' => array(array('Cypriot pound'), array('cent')),
|
|
|
242 |
'CZK' => array(array('Czech koruna'), array('halerz')),
|
|
|
243 |
'DKK' => array(array('Danish krone'), array('ore')),
|
|
|
244 |
'EEK' => array(array('kroon'), array('senti')),
|
|
|
245 |
'EUR' => array(array('euro'), array('euro-cent')),
|
|
|
246 |
'GBP' => array(array('pound', 'pounds'), array('pence', 'pence')),
|
|
|
247 |
'HKD' => array(array('Hong Kong dollar'), array('cent')),
|
|
|
248 |
'HRK' => array(array('Croatian kuna'), array('lipa')),
|
|
|
249 |
'HUF' => array(array('forint'), array('filler')),
|
|
|
250 |
'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
|
|
|
251 |
'ISK' => array(array('Icelandic króna'), array('aurar')),
|
|
|
252 |
'JPY' => array(array('yen'), array('sen')),
|
|
|
253 |
'LTL' => array(array('litas'), array('cent')),
|
|
|
254 |
'LVL' => array(array('lat'), array('sentim')),
|
|
|
255 |
'MKD' => array(array('Macedonian dinar'), array('deni')),
|
|
|
256 |
'MTL' => array(array('Maltese lira'), array('centym')),
|
|
|
257 |
'NOK' => array(array('Norwegian krone'), array('oere')),
|
|
|
258 |
'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
|
|
|
259 |
'ROL' => array(array('Romanian leu'), array('bani')),
|
|
|
260 |
'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
|
|
|
261 |
'SEK' => array(array('Swedish krona'), array('oere')),
|
|
|
262 |
'SIT' => array(array('Tolar'), array('stotinia')),
|
|
|
263 |
'SKK' => array(array('Slovak koruna'), array()),
|
|
|
264 |
'TRL' => array(array('lira'), array('kuruþ')),
|
|
|
265 |
'UAH' => array(array('hryvna'), array('cent')),
|
|
|
266 |
'USD' => array(array('dollar'), array('cent')),
|
|
|
267 |
'YUM' => array(array('dinars'), array('para')),
|
|
|
268 |
'ZAR' => array(array('rand'), array('cent'))
|
|
|
269 |
);
|
|
|
270 |
|
|
|
271 |
/**
|
|
|
272 |
* The default currency name
|
|
|
273 |
* @var string
|
|
|
274 |
* @access public
|
|
|
275 |
*/
|
|
|
276 |
var $def_currency = 'USD'; // American dollar
|
|
|
277 |
|
|
|
278 |
// }}}
|
|
|
279 |
// {{{ toWords()
|
|
|
280 |
|
|
|
281 |
/**
|
|
|
282 |
* Converts a number to its word representation
|
|
|
283 |
* in American English language
|
|
|
284 |
*
|
|
|
285 |
* @param integer $num An integer between -infinity and infinity inclusive :)
|
|
|
286 |
* that need to be converted to words
|
|
|
287 |
* @param integer $power The power of ten for the rest of the number to the right.
|
|
|
288 |
* Optional, defaults to 0.
|
|
|
289 |
* @param integer $powsuffix The power name to be added to the end of the return string.
|
|
|
290 |
* Used internally. Optional, defaults to ''.
|
|
|
291 |
*
|
|
|
292 |
* @return string The corresponding word representation
|
|
|
293 |
*
|
|
|
294 |
* @access public
|
|
|
295 |
* @author Piotr Klaban <makler@man.torun.pl>
|
|
|
296 |
* @since PHP 4.2.3
|
|
|
297 |
*/
|
|
|
298 |
function toWords($num, $power = 0, $powsuffix = '')
|
|
|
299 |
{
|
|
|
300 |
$ret = '';
|
|
|
301 |
|
|
|
302 |
// add a minus sign
|
|
|
303 |
if (substr($num, 0, 1) == '-') {
|
|
|
304 |
$ret = $this->_sep . $this->_minus;
|
|
|
305 |
$num = substr($num, 1);
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
// strip excessive zero signs and spaces
|
|
|
309 |
$num = trim($num);
|
|
|
310 |
$num = preg_replace('/^0+/', '', $num);
|
|
|
311 |
|
|
|
312 |
if (strlen($num) > 3) {
|
|
|
313 |
$maxp = strlen($num)-1;
|
|
|
314 |
$curp = $maxp;
|
|
|
315 |
for ($p = $maxp; $p > 0; --$p) { // power
|
|
|
316 |
|
|
|
317 |
// check for highest power
|
|
|
318 |
if (isset($this->_exponent[$p])) {
|
|
|
319 |
// send substr from $curp to $p
|
|
|
320 |
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
|
|
321 |
$snum = preg_replace('/^0+/', '', $snum);
|
|
|
322 |
if ($snum !== '') {
|
|
|
323 |
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
|
|
324 |
if ($powsuffix != '') {
|
|
|
325 |
$cursuffix .= $this->_sep . $powsuffix;
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
$ret .= $this->toWords($snum, $p, $cursuffix);
|
|
|
329 |
}
|
|
|
330 |
$curp = $p - 1;
|
|
|
331 |
continue;
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
|
|
335 |
if ($num == 0) {
|
|
|
336 |
return $ret;
|
|
|
337 |
}
|
|
|
338 |
} elseif ($num == 0 || $num == '') {
|
|
|
339 |
return $this->_sep . $this->_digits[0];
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
$h = $t = $d = 0;
|
|
|
343 |
|
|
|
344 |
switch(strlen($num)) {
|
|
|
345 |
case 3:
|
|
|
346 |
$h = (int)substr($num, -3, 1);
|
|
|
347 |
|
|
|
348 |
case 2:
|
|
|
349 |
$t = (int)substr($num, -2, 1);
|
|
|
350 |
|
|
|
351 |
case 1:
|
|
|
352 |
$d = (int)substr($num, -1, 1);
|
|
|
353 |
break;
|
|
|
354 |
|
|
|
355 |
case 0:
|
|
|
356 |
return;
|
|
|
357 |
break;
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
if ($h) {
|
|
|
361 |
$ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundred';
|
|
|
362 |
|
|
|
363 |
// in English only - add ' and' for [1-9]01..[1-9]99
|
|
|
364 |
// (also for 1001..1099, 10001..10099 but it is harder)
|
|
|
365 |
// for now it is switched off, maybe some language purists
|
|
|
366 |
// can force me to enable it, or to remove it completely
|
|
|
367 |
// if (($t + $d) > 0)
|
|
|
368 |
// $ret .= $this->_sep . 'and';
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
// ten, twenty etc.
|
|
|
372 |
switch ($t) {
|
|
|
373 |
case 9:
|
|
|
374 |
case 7:
|
|
|
375 |
case 6:
|
|
|
376 |
$ret .= $this->_sep . $this->_digits[$t] . 'ty';
|
|
|
377 |
break;
|
|
|
378 |
|
|
|
379 |
case 8:
|
|
|
380 |
$ret .= $this->_sep . 'eighty';
|
|
|
381 |
break;
|
|
|
382 |
|
|
|
383 |
case 5:
|
|
|
384 |
$ret .= $this->_sep . 'fifty';
|
|
|
385 |
break;
|
|
|
386 |
|
|
|
387 |
case 4:
|
|
|
388 |
$ret .= $this->_sep . 'forty';
|
|
|
389 |
break;
|
|
|
390 |
|
|
|
391 |
case 3:
|
|
|
392 |
$ret .= $this->_sep . 'thirty';
|
|
|
393 |
break;
|
|
|
394 |
|
|
|
395 |
case 2:
|
|
|
396 |
$ret .= $this->_sep . 'twenty';
|
|
|
397 |
break;
|
|
|
398 |
|
|
|
399 |
case 1:
|
|
|
400 |
switch ($d) {
|
|
|
401 |
case 0:
|
|
|
402 |
$ret .= $this->_sep . 'ten';
|
|
|
403 |
break;
|
|
|
404 |
|
|
|
405 |
case 1:
|
|
|
406 |
$ret .= $this->_sep . 'eleven';
|
|
|
407 |
break;
|
|
|
408 |
|
|
|
409 |
case 2:
|
|
|
410 |
$ret .= $this->_sep . 'twelve';
|
|
|
411 |
break;
|
|
|
412 |
|
|
|
413 |
case 3:
|
|
|
414 |
$ret .= $this->_sep . 'thirteen';
|
|
|
415 |
break;
|
|
|
416 |
|
|
|
417 |
case 4:
|
|
|
418 |
case 6:
|
|
|
419 |
case 7:
|
|
|
420 |
case 9:
|
|
|
421 |
$ret .= $this->_sep . $this->_digits[$d] . 'teen';
|
|
|
422 |
break;
|
|
|
423 |
|
|
|
424 |
case 5:
|
|
|
425 |
$ret .= $this->_sep . 'fifteen';
|
|
|
426 |
break;
|
|
|
427 |
|
|
|
428 |
case 8:
|
|
|
429 |
$ret .= $this->_sep . 'eighteen';
|
|
|
430 |
break;
|
|
|
431 |
}
|
|
|
432 |
break;
|
|
|
433 |
}
|
|
|
434 |
|
|
|
435 |
if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
|
|
|
436 |
// add minus sign between [2-9] and digit
|
|
|
437 |
if ($t > 1) {
|
|
|
438 |
$ret .= '-' . $this->_digits[$d];
|
|
|
439 |
} else {
|
|
|
440 |
$ret .= $this->_sep . $this->_digits[$d];
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
if ($power > 0) {
|
|
|
445 |
if (isset($this->_exponent[$power])) {
|
|
|
446 |
$lev = $this->_exponent[$power];
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
if (!isset($lev) || !is_array($lev)) {
|
|
|
450 |
return null;
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
$ret .= $this->_sep . $lev[0];
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
if ($powsuffix != '') {
|
|
|
457 |
$ret .= $this->_sep . $powsuffix;
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
return $ret;
|
|
|
461 |
}
|
|
|
462 |
// }}}
|
|
|
463 |
// {{{ toCurrencyWords()
|
|
|
464 |
|
|
|
465 |
/**
|
|
|
466 |
* Converts a currency value to its word representation
|
|
|
467 |
* (with monetary units) in English language
|
|
|
468 |
*
|
|
|
469 |
* @param integer $int_curr An international currency symbol
|
|
|
470 |
* as defined by the ISO 4217 standard (three characters)
|
|
|
471 |
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
|
|
|
472 |
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
|
|
|
473 |
* Optional. Defaults to false.
|
|
|
474 |
* @param integer $convert_fraction Convert fraction to words (left as numeric if set to false).
|
|
|
475 |
* Optional. Defaults to true.
|
|
|
476 |
*
|
|
|
477 |
* @return string The corresponding word representation for the currency
|
|
|
478 |
*
|
|
|
479 |
* @access public
|
|
|
480 |
* @author Piotr Klaban <makler@man.torun.pl>
|
|
|
481 |
* @since Numbers_Words 0.4
|
|
|
482 |
*/
|
|
|
483 |
function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true)
|
|
|
484 |
{
|
|
|
485 |
$int_curr = strtoupper($int_curr);
|
|
|
486 |
if (!isset($this->_currency_names[$int_curr])) {
|
|
|
487 |
$int_curr = $this->def_currency;
|
|
|
488 |
}
|
|
|
489 |
$curr_names = $this->_currency_names[$int_curr];
|
|
|
490 |
|
|
|
491 |
$ret = trim($this->toWords($decimal));
|
|
|
492 |
$lev = ($decimal == 1) ? 0 : 1;
|
|
|
493 |
if ($lev > 0) {
|
|
|
494 |
if (count($curr_names[0]) > 1) {
|
|
|
495 |
$ret .= $this->_sep . $curr_names[0][$lev];
|
|
|
496 |
} else {
|
|
|
497 |
$ret .= $this->_sep . $curr_names[0][0] . 's';
|
|
|
498 |
}
|
|
|
499 |
} else {
|
|
|
500 |
$ret .= $this->_sep . $curr_names[0][0];
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
if ($fraction !== false) {
|
|
|
504 |
if ($convert_fraction) {
|
|
|
505 |
$ret .= $this->_sep . trim($this->toWords($fraction));
|
|
|
506 |
} else {
|
|
|
507 |
$ret .= $this->_sep . $fraction;
|
|
|
508 |
}
|
|
|
509 |
$lev = ($fraction == 1) ? 0 : 1;
|
|
|
510 |
if ($lev > 0) {
|
|
|
511 |
if (count($curr_names[1]) > 1) {
|
|
|
512 |
$ret .= $this->_sep . $curr_names[1][$lev];
|
|
|
513 |
} else {
|
|
|
514 |
$ret .= $this->_sep . $curr_names[1][0] . 's';
|
|
|
515 |
}
|
|
|
516 |
} else {
|
|
|
517 |
$ret .= $this->_sep . $curr_names[1][0];
|
|
|
518 |
}
|
|
|
519 |
}
|
|
|
520 |
return $ret;
|
|
|
521 |
}
|
|
|
522 |
// }}}
|
|
|
523 |
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
?>
|