| 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.pl.php 293456 2010-01-12 16:44:28Z kouber $
|
|
|
22 |
* @link http://pear.php.net/package/Numbers_Words
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Class for translating numbers into Polish.
|
|
|
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 Polish.
|
|
|
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_pl extends Numbers_Words
|
|
|
47 |
{
|
|
|
48 |
|
|
|
49 |
// {{{ properties
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Locale name
|
|
|
53 |
* @var string
|
|
|
54 |
* @access public
|
|
|
55 |
*/
|
|
|
56 |
var $locale = 'pl';
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Language name in English
|
|
|
60 |
* @var string
|
|
|
61 |
* @access public
|
|
|
62 |
*/
|
|
|
63 |
var $lang = 'Polish';
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Native language name
|
|
|
67 |
* @var string
|
|
|
68 |
* @access public
|
|
|
69 |
*/
|
|
|
70 |
var $lang_native = 'polski';
|
|
|
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 based on:
|
|
|
82 |
* mathematical tables, my memory, and also:
|
|
|
83 |
* http://ux1.math.us.edu.pl/~szyjewski/FAQ/liczby/iony.htm
|
|
|
84 |
* @var array
|
|
|
85 |
* @access private
|
|
|
86 |
*/
|
|
|
87 |
var $_exponent = array(
|
|
|
88 |
// potêga dziesi±tki => liczba pojedyncza, podwójna, mnoga
|
|
|
89 |
|
|
|
90 |
3 => array('tysi±c','tysi±ce','tysiêcy'),
|
|
|
91 |
6 => array('milion','miliony','milionów'),
|
|
|
92 |
9 => array('miliard','miliardy','miliardów'),
|
|
|
93 |
12 => array('bilion','biliony','bilionów'),
|
|
|
94 |
15 => array('biliard','biliardy','biliardów'),
|
|
|
95 |
18 => array('trylion','tryliony','trylionów'),
|
|
|
96 |
21 => array('tryliard','tryliardy','tryliardów'),
|
|
|
97 |
24 => array('kwadrylion','kwadryliony','kwadrylionów'),
|
|
|
98 |
27 => array('kwadryliard','kwadryliardy','kwadryliardów'),
|
|
|
99 |
30 => array('kwintylion','kwintyliony','kwintylionów'),
|
|
|
100 |
33 => array('kwintyliiard','kwintyliardy','kwintyliardów'),
|
|
|
101 |
36 => array('sekstylion','sekstyliony','sekstylionów'),
|
|
|
102 |
39 => array('sekstyliard','sekstyliardy','sekstyliardów'),
|
|
|
103 |
42 => array('septylion','septyliony','septylionów'),
|
|
|
104 |
45 => array('septyliard','septyliardy','septyliardów'),
|
|
|
105 |
48 => array('oktylion','oktyliony','oktylionów'),
|
|
|
106 |
51 => array('oktyliard','oktyliardy','oktyliardów'),
|
|
|
107 |
54 => array('nonylion','nonyliony','nonylionów'),
|
|
|
108 |
57 => array('nonyliard','nonyliardy','nonyliardów'),
|
|
|
109 |
60 => array('decylion','decyliony','decylionów'),
|
|
|
110 |
63 => array('decyliard','decyliardy','decyliardów'),
|
|
|
111 |
100 => array('centylion','centyliony','centylionów'),
|
|
|
112 |
103 => array('centyliard','centyliardy','centyliardów'),
|
|
|
113 |
120 => array('wicylion','wicylion','wicylion'),
|
|
|
114 |
123 => array('wicyliard','wicyliardy','wicyliardów'),
|
|
|
115 |
180 => array('trycylion','trycylion','trycylion'),
|
|
|
116 |
183 => array('trycyliard','trycyliardy','trycyliardów'),
|
|
|
117 |
240 => array('kwadragilion','kwadragilion','kwadragilion'),
|
|
|
118 |
243 => array('kwadragiliard','kwadragiliardy','kwadragiliardów'),
|
|
|
119 |
300 => array('kwinkwagilion','kwinkwagilion','kwinkwagilion'),
|
|
|
120 |
303 => array('kwinkwagiliard','kwinkwagiliardy','kwinkwagiliardów'),
|
|
|
121 |
360 => array('seskwilion','seskwilion','seskwilion'),
|
|
|
122 |
363 => array('seskwiliard','seskwiliardy','seskwiliardów'),
|
|
|
123 |
420 => array('septagilion','septagilion','septagilion'),
|
|
|
124 |
423 => array('septagiliard','septagiliardy','septagiliardów'),
|
|
|
125 |
480 => array('oktogilion','oktogilion','oktogilion'),
|
|
|
126 |
483 => array('oktogiliard','oktogiliardy','oktogiliardów'),
|
|
|
127 |
540 => array('nonagilion','nonagilion','nonagilion'),
|
|
|
128 |
543 => array('nonagiliard','nonagiliardy','nonagiliardów'),
|
|
|
129 |
600 => array('centylion','centyliony','centylionów'),
|
|
|
130 |
603 => array('centyliard','centyliardy','centyliardów'),
|
|
|
131 |
6000018 => array('milinilitrylion','milinilitryliony','milinilitrylionów')
|
|
|
132 |
);
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* The array containing the digits (indexed by the digits themselves).
|
|
|
136 |
* @var array
|
|
|
137 |
* @access private
|
|
|
138 |
*/
|
|
|
139 |
var $_digits = array(
|
|
|
140 |
|
|
|
141 |
'piêæ', 'sze¶æ', 'siedem', 'osiem', 'dziewiêæ'
|
|
|
142 |
);
|
|
|
143 |
|
|
|
144 |
/**
|
|
|
145 |
* The word separator
|
|
|
146 |
* @var string
|
|
|
147 |
* @access private
|
|
|
148 |
*/
|
|
|
149 |
var $_sep = ' ';
|
|
|
150 |
|
|
|
151 |
/**
|
|
|
152 |
* The currency names (based on the below links,
|
|
|
153 |
* informations from central bank websites and on encyclopedias)
|
|
|
154 |
*
|
|
|
155 |
* @var array
|
|
|
156 |
* @link http://www.xe.com/iso4217.htm Currency codes
|
|
|
157 |
* @link http://www.republika.pl/geographia/peuropy.htm Europe review
|
|
|
158 |
* @link http://pieniadz.hoga.pl/waluty_objasnienia.asp Currency service
|
|
|
159 |
* @access private
|
|
|
160 |
*/
|
|
|
161 |
var $_currency_names = array(
|
|
|
162 |
'ALL' => array(array('lek','leki','leków'), array('quindarka','quindarki','quindarek')),
|
|
|
163 |
'AUD' => array(array('dolar australijski', 'dolary australijskie', 'dolarów australijskich'), array('cent', 'centy', 'centów')),
|
|
|
164 |
'BAM' => array(array('marka','marki','marek'), array('fenig','fenigi','fenigów')),
|
|
|
165 |
'BGN' => array(array('lew','lewy','lew'), array('stotinka','stotinki','stotinek')),
|
|
|
166 |
'BRL' => array(array('real','reale','realów'), array('centavos','centavos','centavos')),
|
|
|
167 |
'BYR' => array(array('rubel','ruble','rubli'), array('kopiejka','kopiejki','kopiejek')),
|
|
|
168 |
'CAD' => array(array('dolar kanadyjski', 'dolary kanadyjskie', 'dolarów kanadyjskich'), array('cent', 'centy', 'centów')),
|
|
|
169 |
'CHF' => array(array('frank szwajcarski','franki szwajcarskie','franków szwajcarskich'), array('rapp','rappy','rappów')),
|
|
|
170 |
'CYP' => array(array('funt cypryjski','funty cypryjskie','funtów cypryjskich'), array('cent', 'centy', 'centów')),
|
|
|
171 |
'CZK' => array(array('korona czeska','korony czeskie','koron czeskich'), array('halerz','halerze','halerzy')),
|
|
|
172 |
'DKK' => array(array('korona duñska','korony duñskie','koron duñskich'), array('ore','ore','ore')),
|
|
|
173 |
'EEK' => array(array('korona estoñska','korony estoñskie','koron estoñskich'), array('senti','senti','senti')),
|
|
|
174 |
'EUR' => array(array('euro', 'euro', 'euro'), array('eurocent', 'eurocenty', 'eurocentów')),
|
|
|
175 |
'GBP' => array(array('funt szterling','funty szterlingi','funtów szterlingów'), array('pens','pensy','pensów')),
|
|
|
176 |
'HKD' => array(array('dolar Hongkongu','dolary Hongkongu','dolarów Hongkongu'), array('cent', 'centy', 'centów')),
|
|
|
177 |
'HRK' => array(array('kuna','kuny','kun'), array('lipa','lipy','lip')),
|
|
|
178 |
'HUF' => array(array('forint','forinty','forintów'), array('filler','fillery','fillerów')),
|
|
|
179 |
'ILS' => array(array('nowy szekel','nowe szekele','nowych szekeli'), array('agora','agory','agorot')),
|
|
|
180 |
'ISK' => array(array('korona islandzka','korony islandzkie','koron islandzkich'), array('aurar','aurar','aurar')),
|
|
|
181 |
'JPY' => array(array('jen','jeny','jenów'), array('sen','seny','senów')),
|
|
|
182 |
'LTL' => array(array('lit','lity','litów'), array('cent', 'centy', 'centów')),
|
|
|
183 |
'LVL' => array(array('³at','³aty','³atów'), array('sentim','sentimy','sentimów')),
|
|
|
184 |
'MKD' => array(array('denar','denary','denarów'), array('deni','deni','deni')),
|
|
|
185 |
'MTL' => array(array('lira maltañska','liry maltañskie','lir maltañskich'), array('centym','centymy','centymów')),
|
|
|
186 |
'NOK' => array(array('korona norweska','korony norweskie','koron norweskich'), array('oere','oere','oere')),
|
|
|
187 |
'PLN' => array(array('z³oty', 'z³ote', 'z³otych'), array('grosz', 'grosze', 'groszy')),
|
|
|
188 |
'ROL' => array(array('lej','leje','lei'), array('bani','bani','bani')),
|
|
|
189 |
'RUB' => array(array('rubel','ruble','rubli'), array('kopiejka','kopiejki','kopiejek')),
|
|
|
190 |
'SEK' => array(array('korona szwedzka','korony szwedzkie','koron szweckich'), array('oere','oere','oere')),
|
|
|
191 |
'SIT' => array(array('tolar','tolary','tolarów'), array('stotinia','stotinie','stotini')),
|
|
|
192 |
'SKK' => array(array('korona s³owacka','korony s³owackie','koron s³owackich'), array('halerz','halerze','halerzy')),
|
|
|
193 |
'TRL' => array(array('lira turecka','liry tureckie','lir tureckich'), array('kurusza','kurysze','kuruszy')),
|
|
|
194 |
'UAH' => array(array('hrywna','hrywna','hrywna'), array('cent', 'centy', 'centów')),
|
|
|
195 |
'USD' => array(array('dolar','dolary','dolarów'), array('cent', 'centy', 'centów')),
|
|
|
196 |
'YUM' => array(array('dinar','dinary','dinarów'), array('para','para','para')),
|
|
|
197 |
'ZAR' => array(array('rand','randy','randów'), array('cent', 'centy', 'centów'))
|
|
|
198 |
);
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* The default currency name
|
|
|
202 |
* @var string
|
|
|
203 |
* @access public
|
|
|
204 |
*/
|
|
|
205 |
var $def_currency = 'PLN'; // Polish zloty
|
|
|
206 |
|
|
|
207 |
// }}}
|
|
|
208 |
// {{{ toWords()
|
|
|
209 |
|
|
|
210 |
/**
|
|
|
211 |
* Converts a number to its word representation
|
|
|
212 |
* in Polish language
|
|
|
213 |
*
|
|
|
214 |
* @param integer $num An integer between -infinity and infinity inclusive :)
|
|
|
215 |
* that need to be converted to words
|
|
|
216 |
* @param integer $power The power of ten for the rest of the number to the right.
|
|
|
217 |
* Optional, defaults to 0.
|
|
|
218 |
* @param integer $powsuffix The power name to be added to the end of the return string.
|
|
|
219 |
* Used internally. Optional, defaults to ''.
|
|
|
220 |
*
|
|
|
221 |
* @return string The corresponding word representation
|
|
|
222 |
*
|
|
|
223 |
* @access public
|
|
|
224 |
* @author Piotr Klaban <makler@man.torun.pl>
|
|
|
225 |
* @since PHP 4.2.3
|
|
|
226 |
*/
|
|
|
227 |
function toWords($num, $power = 0, $powsuffix = '')
|
|
|
228 |
{
|
|
|
229 |
$ret = '';
|
|
|
230 |
|
|
|
231 |
// add a minus sign
|
|
|
232 |
if (substr($num, 0, 1) == '-') {
|
|
|
233 |
$ret = $this->_sep . $this->_minus;
|
|
|
234 |
$num = substr($num, 1);
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
// strip excessive zero signs and spaces
|
|
|
238 |
$num = trim($num);
|
|
|
239 |
$num = preg_replace('/^0+/', '', $num);
|
|
|
240 |
|
|
|
241 |
if (strlen($num) > 3) {
|
|
|
242 |
$maxp = strlen($num)-1;
|
|
|
243 |
$curp = $maxp;
|
|
|
244 |
for ($p = $maxp; $p > 0; --$p) { // power
|
|
|
245 |
|
|
|
246 |
// check for highest power
|
|
|
247 |
if (isset($this->_exponent[$p])) {
|
|
|
248 |
// send substr from $curp to $p
|
|
|
249 |
$snum = substr($num, $maxp - $curp, $curp - $p + 1);
|
|
|
250 |
$snum = preg_replace('/^0+/', '', $snum);
|
|
|
251 |
if ($snum !== '') {
|
|
|
252 |
$cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
|
|
|
253 |
if ($powsuffix != '') {
|
|
|
254 |
$cursuffix .= $this->_sep . $powsuffix;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
$ret .= $this->toWords($snum, $p, $cursuffix);
|
|
|
258 |
}
|
|
|
259 |
$curp = $p - 1;
|
|
|
260 |
continue;
|
|
|
261 |
}
|
|
|
262 |
}
|
|
|
263 |
$num = substr($num, $maxp - $curp, $curp - $p + 1);
|
|
|
264 |
if ($num == 0) {
|
|
|
265 |
return $ret;
|
|
|
266 |
}
|
|
|
267 |
} elseif ($num == 0 || $num == '') {
|
|
|
268 |
return $this->_sep . $this->_digits[0];
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
$h = $t = $d = 0;
|
|
|
272 |
|
|
|
273 |
switch(strlen($num)) {
|
|
|
274 |
case 3:
|
|
|
275 |
$h = (int)substr($num, -3, 1);
|
|
|
276 |
|
|
|
277 |
case 2:
|
|
|
278 |
$t = (int)substr($num, -2, 1);
|
|
|
279 |
|
|
|
280 |
case 1:
|
|
|
281 |
$d = (int)substr($num, -1, 1);
|
|
|
282 |
break;
|
|
|
283 |
|
|
|
284 |
case 0:
|
|
|
285 |
return;
|
|
|
286 |
break;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
switch ($h) {
|
|
|
290 |
case 9:
|
|
|
291 |
$ret .= $this->_sep . 'dziewiêæset';
|
|
|
292 |
break;
|
|
|
293 |
|
|
|
294 |
case 8:
|
|
|
295 |
$ret .= $this->_sep . 'osiemset';
|
|
|
296 |
break;
|
|
|
297 |
|
|
|
298 |
case 7:
|
|
|
299 |
$ret .= $this->_sep . 'siedemset';
|
|
|
300 |
break;
|
|
|
301 |
|
|
|
302 |
case 6:
|
|
|
303 |
$ret .= $this->_sep . 'sze¶æset';
|
|
|
304 |
break;
|
|
|
305 |
|
|
|
306 |
case 5:
|
|
|
307 |
$ret .= $this->_sep . 'piêæset';
|
|
|
308 |
break;
|
|
|
309 |
|
|
|
310 |
case 4:
|
|
|
311 |
$ret .= $this->_sep . 'czterysta';
|
|
|
312 |
break;
|
|
|
313 |
|
|
|
314 |
case 3:
|
|
|
315 |
$ret .= $this->_sep . 'trzysta';
|
|
|
316 |
break;
|
|
|
317 |
|
|
|
318 |
case 2:
|
|
|
319 |
$ret .= $this->_sep . 'dwie¶cie';
|
|
|
320 |
break;
|
|
|
321 |
|
|
|
322 |
case 1:
|
|
|
323 |
$ret .= $this->_sep . 'sto';
|
|
|
324 |
break;
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
switch ($t) {
|
|
|
328 |
case 9:
|
|
|
329 |
case 8:
|
|
|
330 |
case 7:
|
|
|
331 |
case 6:
|
|
|
332 |
case 5:
|
|
|
333 |
$ret .= $this->_sep . $this->_digits[$t] . 'dziesi±t';
|
|
|
334 |
break;
|
|
|
335 |
|
|
|
336 |
case 4:
|
|
|
337 |
$ret .= $this->_sep . 'czterdzie¶ci';
|
|
|
338 |
break;
|
|
|
339 |
|
|
|
340 |
case 3:
|
|
|
341 |
$ret .= $this->_sep . 'trzydzie¶ci';
|
|
|
342 |
break;
|
|
|
343 |
|
|
|
344 |
case 2:
|
|
|
345 |
$ret .= $this->_sep . 'dwadzie¶cia';
|
|
|
346 |
break;
|
|
|
347 |
|
|
|
348 |
case 1:
|
|
|
349 |
switch ($d) {
|
|
|
350 |
case 0:
|
|
|
351 |
$ret .= $this->_sep . 'dziesiêæ';
|
|
|
352 |
break;
|
|
|
353 |
|
|
|
354 |
case 1:
|
|
|
355 |
$ret .= $this->_sep . 'jedena¶cie';
|
|
|
356 |
break;
|
|
|
357 |
|
|
|
358 |
case 2:
|
|
|
359 |
case 3:
|
|
|
360 |
case 7:
|
|
|
361 |
case 8:
|
|
|
362 |
$ret .= $this->_sep . $this->_digits[$d] . 'na¶cie';
|
|
|
363 |
break;
|
|
|
364 |
|
|
|
365 |
case 4:
|
|
|
366 |
$ret .= $this->_sep . 'czterna¶cie';
|
|
|
367 |
break;
|
|
|
368 |
|
|
|
369 |
case 5:
|
|
|
370 |
$ret .= $this->_sep . 'piêtna¶cie';
|
|
|
371 |
break;
|
|
|
372 |
|
|
|
373 |
case 6:
|
|
|
374 |
$ret .= $this->_sep . 'szesna¶cie';
|
|
|
375 |
break;
|
|
|
376 |
|
|
|
377 |
case 9:
|
|
|
378 |
$ret .= $this->_sep . 'dziewiêtna¶cie';
|
|
|
379 |
break;
|
|
|
380 |
}
|
|
|
381 |
break;
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
if ($t != 1 && $d > 0) {
|
|
|
385 |
$ret .= $this->_sep . $this->_digits[$d];
|
|
|
386 |
}
|
|
|
387 |
|
|
|
388 |
if ($t == 1) {
|
|
|
389 |
$d = 0;
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
if (( $h + $t ) > 0 && $d == 1) {
|
|
|
393 |
$d = 0;
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
if ($power > 0) {
|
|
|
397 |
if (isset($this->_exponent[$power])) {
|
|
|
398 |
$lev = $this->_exponent[$power];
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
if (!isset($lev) || !is_array($lev)) {
|
|
|
402 |
return null;
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
switch ($d) {
|
|
|
406 |
case 1:
|
|
|
407 |
$suf = $lev[0];
|
|
|
408 |
break;
|
|
|
409 |
case 2:
|
|
|
410 |
case 3:
|
|
|
411 |
case 4:
|
|
|
412 |
$suf = $lev[1];
|
|
|
413 |
break;
|
|
|
414 |
case 0:
|
|
|
415 |
case 5:
|
|
|
416 |
case 6:
|
|
|
417 |
case 7:
|
|
|
418 |
case 8:
|
|
|
419 |
case 9:
|
|
|
420 |
$suf = $lev[2];
|
|
|
421 |
break;
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
$ret .= $this->_sep . $suf;
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
if ($powsuffix != '') {
|
|
|
428 |
$ret .= $this->_sep . $powsuffix;
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
return $ret;
|
|
|
432 |
}
|
|
|
433 |
// }}}
|
|
|
434 |
// {{{ toCurrencyWords()
|
|
|
435 |
|
|
|
436 |
/**
|
|
|
437 |
* Converts a currency value to its word representation
|
|
|
438 |
* (with monetary units) in Polish language
|
|
|
439 |
*
|
|
|
440 |
* @param integer $int_curr An international currency symbol
|
|
|
441 |
* as defined by the ISO 4217 standard (three characters)
|
|
|
442 |
* @param integer $decimal A money total amount without fraction part (e.g. amount of dollars)
|
|
|
443 |
* @param integer $fraction Fractional part of the money amount (e.g. amount of cents)
|
|
|
444 |
* Optional. Defaults to false.
|
|
|
445 |
* @param integer $convert_fraction Convert fraction to words (left as numeric if set to false).
|
|
|
446 |
* Optional. Defaults to true.
|
|
|
447 |
*
|
|
|
448 |
* @return string The corresponding word representation for the currency
|
|
|
449 |
*
|
|
|
450 |
* @access public
|
|
|
451 |
* @author Piotr Klaban <makler@man.torun.pl>
|
|
|
452 |
* @since Numbers_Words 0.4
|
|
|
453 |
*/
|
|
|
454 |
function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true)
|
|
|
455 |
{
|
|
|
456 |
$int_curr = strtoupper($int_curr);
|
|
|
457 |
if (!isset($this->_currency_names[$int_curr])) {
|
|
|
458 |
$int_curr = $this->def_currency;
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
$curr_names = $this->_currency_names[$int_curr];
|
|
|
462 |
|
|
|
463 |
$ret = trim($this->toWords($decimal));
|
|
|
464 |
$lev = $this->_get_numlevel($decimal);
|
|
|
465 |
$ret .= $this->_sep . $curr_names[0][$lev];
|
|
|
466 |
|
|
|
467 |
if ($fraction !== false) {
|
|
|
468 |
if ($convert_fraction) {
|
|
|
469 |
$ret .= $this->_sep . trim($this->toWords($fraction));
|
|
|
470 |
} else {
|
|
|
471 |
$ret .= $this->_sep . $fraction;
|
|
|
472 |
}
|
|
|
473 |
$lev = $this->_get_numlevel($fraction);
|
|
|
474 |
$ret .= $this->_sep . $curr_names[1][$lev];
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
return $ret;
|
|
|
478 |
}
|
|
|
479 |
// }}}
|
|
|
480 |
// {{{ _get_numlevel()
|
|
|
481 |
|
|
|
482 |
/**
|
|
|
483 |
* Returns grammatical "level" of the number - this is necessary
|
|
|
484 |
* for choosing the right suffix for exponents and currency names.
|
|
|
485 |
*
|
|
|
486 |
* @param integer $num An integer between -infinity and infinity inclusive
|
|
|
487 |
* that need to be converted to words
|
|
|
488 |
*
|
|
|
489 |
* @return integer The grammatical "level" of the number.
|
|
|
490 |
*
|
|
|
491 |
* @access private
|
|
|
492 |
* @author Piotr Klaban <makler@man.torun.pl>
|
|
|
493 |
* @since Numbers_Words 0.4
|
|
|
494 |
*/
|
|
|
495 |
function _get_numlevel($num)
|
|
|
496 |
{
|
|
|
497 |
if (strlen($num) > 3) {
|
|
|
498 |
$num = substr($num, -3);
|
|
|
499 |
}
|
|
|
500 |
$num = (int) $num;
|
|
|
501 |
|
|
|
502 |
$h = $t = $d = $lev = 0;
|
|
|
503 |
|
|
|
504 |
switch (strlen($num)) {
|
|
|
505 |
case 3:
|
|
|
506 |
$h = (int)substr($num, -3, 1);
|
|
|
507 |
|
|
|
508 |
case 2:
|
|
|
509 |
$t = (int)substr($num, -2, 1);
|
|
|
510 |
|
|
|
511 |
case 1:
|
|
|
512 |
$d = (int)substr($num, -1, 1);
|
|
|
513 |
break;
|
|
|
514 |
|
|
|
515 |
case 0:
|
|
|
516 |
return $lev;
|
|
|
517 |
break;
|
|
|
518 |
}
|
|
|
519 |
|
|
|
520 |
if ($t == 1) {
|
|
|
521 |
$d = 0;
|
|
|
522 |
}
|
|
|
523 |
|
|
|
524 |
if (( $h + $t ) > 0 && $d == 1) {
|
|
|
525 |
$d = 0;
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
switch ($d) {
|
|
|
529 |
case 1:
|
|
|
530 |
$lev = 0;
|
|
|
531 |
break;
|
|
|
532 |
case 2:
|
|
|
533 |
case 3:
|
|
|
534 |
case 4:
|
|
|
535 |
$lev = 1;
|
|
|
536 |
break;
|
|
|
537 |
default:
|
|
|
538 |
$lev = 2;
|
|
|
539 |
}
|
|
|
540 |
return $lev;
|
|
|
541 |
}
|
|
|
542 |
// }}}
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
?>
|