xref: /php-src/ext/bcmath/tests/number/cast.phpt (revision fad899e5)
1--TEST--
2BcMath\Number cast
3--EXTENSIONS--
4bcmath
5--FILE--
6<?php
7
8$values = [
9    '0',
10    '0.0',
11    '2',
12    '1234',
13    '12.0004',
14    '0.1230',
15    1,
16    12345,
17    '-0',
18    '-0.0',
19    '-2',
20    '-1234',
21    '-12.0004',
22    '-0.1230',
23    -1,
24    -12345,
25];
26
27foreach ($values as $value) {
28    $num = new BcMath\Number($value);
29    echo "========== {$value} ==========\n";
30    var_dump([
31        'bool' => (bool) $num,
32        'string' => (string) $num,
33        'array' => (array) $num,
34    ]);
35    echo "\n";
36}
37?>
38--EXPECT--
39========== 0 ==========
40array(3) {
41  ["bool"]=>
42  bool(false)
43  ["string"]=>
44  string(1) "0"
45  ["array"]=>
46  array(2) {
47    ["value"]=>
48    string(1) "0"
49    ["scale"]=>
50    int(0)
51  }
52}
53
54========== 0.0 ==========
55array(3) {
56  ["bool"]=>
57  bool(false)
58  ["string"]=>
59  string(3) "0.0"
60  ["array"]=>
61  array(2) {
62    ["value"]=>
63    string(3) "0.0"
64    ["scale"]=>
65    int(1)
66  }
67}
68
69========== 2 ==========
70array(3) {
71  ["bool"]=>
72  bool(true)
73  ["string"]=>
74  string(1) "2"
75  ["array"]=>
76  array(2) {
77    ["value"]=>
78    string(1) "2"
79    ["scale"]=>
80    int(0)
81  }
82}
83
84========== 1234 ==========
85array(3) {
86  ["bool"]=>
87  bool(true)
88  ["string"]=>
89  string(4) "1234"
90  ["array"]=>
91  array(2) {
92    ["value"]=>
93    string(4) "1234"
94    ["scale"]=>
95    int(0)
96  }
97}
98
99========== 12.0004 ==========
100array(3) {
101  ["bool"]=>
102  bool(true)
103  ["string"]=>
104  string(7) "12.0004"
105  ["array"]=>
106  array(2) {
107    ["value"]=>
108    string(7) "12.0004"
109    ["scale"]=>
110    int(4)
111  }
112}
113
114========== 0.1230 ==========
115array(3) {
116  ["bool"]=>
117  bool(true)
118  ["string"]=>
119  string(6) "0.1230"
120  ["array"]=>
121  array(2) {
122    ["value"]=>
123    string(6) "0.1230"
124    ["scale"]=>
125    int(4)
126  }
127}
128
129========== 1 ==========
130array(3) {
131  ["bool"]=>
132  bool(true)
133  ["string"]=>
134  string(1) "1"
135  ["array"]=>
136  array(2) {
137    ["value"]=>
138    string(1) "1"
139    ["scale"]=>
140    int(0)
141  }
142}
143
144========== 12345 ==========
145array(3) {
146  ["bool"]=>
147  bool(true)
148  ["string"]=>
149  string(5) "12345"
150  ["array"]=>
151  array(2) {
152    ["value"]=>
153    string(5) "12345"
154    ["scale"]=>
155    int(0)
156  }
157}
158
159========== -0 ==========
160array(3) {
161  ["bool"]=>
162  bool(false)
163  ["string"]=>
164  string(1) "0"
165  ["array"]=>
166  array(2) {
167    ["value"]=>
168    string(1) "0"
169    ["scale"]=>
170    int(0)
171  }
172}
173
174========== -0.0 ==========
175array(3) {
176  ["bool"]=>
177  bool(false)
178  ["string"]=>
179  string(3) "0.0"
180  ["array"]=>
181  array(2) {
182    ["value"]=>
183    string(3) "0.0"
184    ["scale"]=>
185    int(1)
186  }
187}
188
189========== -2 ==========
190array(3) {
191  ["bool"]=>
192  bool(true)
193  ["string"]=>
194  string(2) "-2"
195  ["array"]=>
196  array(2) {
197    ["value"]=>
198    string(2) "-2"
199    ["scale"]=>
200    int(0)
201  }
202}
203
204========== -1234 ==========
205array(3) {
206  ["bool"]=>
207  bool(true)
208  ["string"]=>
209  string(5) "-1234"
210  ["array"]=>
211  array(2) {
212    ["value"]=>
213    string(5) "-1234"
214    ["scale"]=>
215    int(0)
216  }
217}
218
219========== -12.0004 ==========
220array(3) {
221  ["bool"]=>
222  bool(true)
223  ["string"]=>
224  string(8) "-12.0004"
225  ["array"]=>
226  array(2) {
227    ["value"]=>
228    string(8) "-12.0004"
229    ["scale"]=>
230    int(4)
231  }
232}
233
234========== -0.1230 ==========
235array(3) {
236  ["bool"]=>
237  bool(true)
238  ["string"]=>
239  string(7) "-0.1230"
240  ["array"]=>
241  array(2) {
242    ["value"]=>
243    string(7) "-0.1230"
244    ["scale"]=>
245    int(4)
246  }
247}
248
249========== -1 ==========
250array(3) {
251  ["bool"]=>
252  bool(true)
253  ["string"]=>
254  string(2) "-1"
255  ["array"]=>
256  array(2) {
257    ["value"]=>
258    string(2) "-1"
259    ["scale"]=>
260    int(0)
261  }
262}
263
264========== -12345 ==========
265array(3) {
266  ["bool"]=>
267  bool(true)
268  ["string"]=>
269  string(6) "-12345"
270  ["array"]=>
271  array(2) {
272    ["value"]=>
273    string(6) "-12345"
274    ["scale"]=>
275    int(0)
276  }
277}
278