-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFunctionToWords.php
More file actions
74 lines (60 loc) · 2.25 KB
/
Copy pathFunctionToWords.php
File metadata and controls
74 lines (60 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
$numb = array('nulle', 'viens', 'divi', 'trīs', 'četri', 'pieci', 'seši', 'septiņi', 'astoņi', 'deviņi', 'desmit');
$tens = array('', 'vien', 'div', 'trīs', 'četr', 'piec', 'seš', 'septiņ', 'astoņ', 'deviņ');
$bigones = array(100 => 'simti', 1000 => 'tūkstoši', 1000000 => 'miljoni', 1000000000 => 'miljardi');
function toWords($num)
{
global $numb, $tens, $bigones, $santimes;
$num = number_format($num, 2, '.', '');
$numParts = explode('.', $num);
$lsString = '';
//apstrādā centus
if ($numParts[1] > 0) {
$santString = tenWords($numParts[1]) .
(($numParts[1] % 10 == 1 && $numParts[1] != 11) ? 'cents ' : 'centi ');
} else {
$santString = 'nulle centi';
}
//apstrādā eiro
$thousands = floor($numParts[0] / 1000);
if (99 < $thousands) {
return ('ERROR: Nevar konvertēt lielāku summu par 99 999.99');
}
if (!empty($thousands)) {
$lsString = tenWords($thousands) .
(($thousands % 10 == 1 && $thousands != 11) ? ' tūkstotis ' : 'tūkstoši ');
}
$hundreds = floor(substr($numParts[0], -3) / 100);
if (!empty($hundreds)) {
$lsString .= $numb[intval($hundreds)] .
($hundreds % 10 == 1 ? ' simts ' : ' simti ');
}
if (strlen($numParts[0]) == 1) {
$tenLats = substr($numParts[0], -1);
} else {
$tenLats = substr($numParts[0], -2);
}
if ($tenLats > 0 || empty($lsString)) {
$lsString .= tenWords($tenLats);
}
$lsString .= (($tenLats % 10 == 1 && $tenLats != 11) ? 'eiro' : 'eiro');
$text = $lsString . ' ' . $santString;
return $text;
}
function tenWords($num)
{
global $tens, $numb;
if ($num > 19) {
$firstDigit = substr($num, 0, 1);
$secondDigit = substr($num, 1, 1);
if ($secondDigit == 0)
return $tens[$firstDigit] . 'desmit ';
else
return $tens[$firstDigit] . 'desmit ' . $numb[$secondDigit] . ' ';
} elseif ($num <= 19 AND $num > 10) {
return $tens[$num % 10] . 'padsmit ';
} elseif ($num <= 10) {
return $numb[intval($num)] . ' ';
}
}
?>