1--TEST--
2Test number_format() - test function with different decimal places
3--FILE--
4<?php
5
6define("MAX_INT32", 2147483647);
7define("MIN_INT32", -2147483647 - 1);
8
9$values = array(
10    1.5151,
11    15.151,
12    151.51,
13    1515.1,
14    15151,
15    -1.5151,
16    -15.151,
17    -151.51,
18    -1515.1,
19    -15151,
20    999,
21    -999,
22    999.0,
23    -999.0,
24    999999,
25    -999999,
26    999999.0,
27    -999999.0,
28    MAX_INT32,
29    MIN_INT32,
30);
31
32$decimals = array(0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5, PHP_INT_MIN);
33
34foreach ($values as $value) {
35    echo 'testing ';
36    var_dump($value);
37
38    foreach ($decimals as $decimal) {
39        echo '... with decimal places of ' . $decimal . ': ';
40        var_dump(number_format($value, $decimal));
41    }
42}
43
44?>
45--EXPECTF--
46testing float(1.5151)
47... with decimal places of 0: string(1) "2"
48... with decimal places of 1: string(3) "1.5"
49... with decimal places of 2: string(4) "1.52"
50... with decimal places of 3: string(5) "1.515"
51... with decimal places of 4: string(6) "1.5151"
52... with decimal places of 5: string(7) "1.51510"
53... with decimal places of -1: string(1) "0"
54... with decimal places of -2: string(1) "0"
55... with decimal places of -3: string(1) "0"
56... with decimal places of -4: string(1) "0"
57... with decimal places of -5: string(1) "0"
58... with decimal places of %i: string(1) "0"
59testing float(15.151)
60... with decimal places of 0: string(2) "15"
61... with decimal places of 1: string(4) "15.2"
62... with decimal places of 2: string(5) "15.15"
63... with decimal places of 3: string(6) "15.151"
64... with decimal places of 4: string(7) "15.1510"
65... with decimal places of 5: string(8) "15.15100"
66... with decimal places of -1: string(2) "20"
67... with decimal places of -2: string(1) "0"
68... with decimal places of -3: string(1) "0"
69... with decimal places of -4: string(1) "0"
70... with decimal places of -5: string(1) "0"
71... with decimal places of %i: string(1) "0"
72testing float(151.51)
73... with decimal places of 0: string(3) "152"
74... with decimal places of 1: string(5) "151.5"
75... with decimal places of 2: string(6) "151.51"
76... with decimal places of 3: string(7) "151.510"
77... with decimal places of 4: string(8) "151.5100"
78... with decimal places of 5: string(9) "151.51000"
79... with decimal places of -1: string(3) "150"
80... with decimal places of -2: string(3) "200"
81... with decimal places of -3: string(1) "0"
82... with decimal places of -4: string(1) "0"
83... with decimal places of -5: string(1) "0"
84... with decimal places of %i: string(1) "0"
85testing float(1515.1)
86... with decimal places of 0: string(5) "1,515"
87... with decimal places of 1: string(7) "1,515.1"
88... with decimal places of 2: string(8) "1,515.10"
89... with decimal places of 3: string(9) "1,515.100"
90... with decimal places of 4: string(10) "1,515.1000"
91... with decimal places of 5: string(11) "1,515.10000"
92... with decimal places of -1: string(5) "1,520"
93... with decimal places of -2: string(5) "1,500"
94... with decimal places of -3: string(5) "2,000"
95... with decimal places of -4: string(1) "0"
96... with decimal places of -5: string(1) "0"
97... with decimal places of %i: string(1) "0"
98testing int(15151)
99... with decimal places of 0: string(6) "15,151"
100... with decimal places of 1: string(8) "15,151.0"
101... with decimal places of 2: string(9) "15,151.00"
102... with decimal places of 3: string(10) "15,151.000"
103... with decimal places of 4: string(11) "15,151.0000"
104... with decimal places of 5: string(12) "15,151.00000"
105... with decimal places of -1: string(6) "15,150"
106... with decimal places of -2: string(6) "15,200"
107... with decimal places of -3: string(6) "15,000"
108... with decimal places of -4: string(6) "20,000"
109... with decimal places of -5: string(1) "0"
110... with decimal places of %i: string(1) "0"
111testing float(-1.5151)
112... with decimal places of 0: string(2) "-2"
113... with decimal places of 1: string(4) "-1.5"
114... with decimal places of 2: string(5) "-1.52"
115... with decimal places of 3: string(6) "-1.515"
116... with decimal places of 4: string(7) "-1.5151"
117... with decimal places of 5: string(8) "-1.51510"
118... with decimal places of -1: string(1) "0"
119... with decimal places of -2: string(1) "0"
120... with decimal places of -3: string(1) "0"
121... with decimal places of -4: string(1) "0"
122... with decimal places of -5: string(1) "0"
123... with decimal places of %i: string(1) "0"
124testing float(-15.151)
125... with decimal places of 0: string(3) "-15"
126... with decimal places of 1: string(5) "-15.2"
127... with decimal places of 2: string(6) "-15.15"
128... with decimal places of 3: string(7) "-15.151"
129... with decimal places of 4: string(8) "-15.1510"
130... with decimal places of 5: string(9) "-15.15100"
131... with decimal places of -1: string(3) "-20"
132... with decimal places of -2: string(1) "0"
133... with decimal places of -3: string(1) "0"
134... with decimal places of -4: string(1) "0"
135... with decimal places of -5: string(1) "0"
136... with decimal places of %i: string(1) "0"
137testing float(-151.51)
138... with decimal places of 0: string(4) "-152"
139... with decimal places of 1: string(6) "-151.5"
140... with decimal places of 2: string(7) "-151.51"
141... with decimal places of 3: string(8) "-151.510"
142... with decimal places of 4: string(9) "-151.5100"
143... with decimal places of 5: string(10) "-151.51000"
144... with decimal places of -1: string(4) "-150"
145... with decimal places of -2: string(4) "-200"
146... with decimal places of -3: string(1) "0"
147... with decimal places of -4: string(1) "0"
148... with decimal places of -5: string(1) "0"
149... with decimal places of %i: string(1) "0"
150testing float(-1515.1)
151... with decimal places of 0: string(6) "-1,515"
152... with decimal places of 1: string(8) "-1,515.1"
153... with decimal places of 2: string(9) "-1,515.10"
154... with decimal places of 3: string(10) "-1,515.100"
155... with decimal places of 4: string(11) "-1,515.1000"
156... with decimal places of 5: string(12) "-1,515.10000"
157... with decimal places of -1: string(6) "-1,520"
158... with decimal places of -2: string(6) "-1,500"
159... with decimal places of -3: string(6) "-2,000"
160... with decimal places of -4: string(1) "0"
161... with decimal places of -5: string(1) "0"
162... with decimal places of %i: string(1) "0"
163testing int(-15151)
164... with decimal places of 0: string(7) "-15,151"
165... with decimal places of 1: string(9) "-15,151.0"
166... with decimal places of 2: string(10) "-15,151.00"
167... with decimal places of 3: string(11) "-15,151.000"
168... with decimal places of 4: string(12) "-15,151.0000"
169... with decimal places of 5: string(13) "-15,151.00000"
170... with decimal places of -1: string(7) "-15,150"
171... with decimal places of -2: string(7) "-15,200"
172... with decimal places of -3: string(7) "-15,000"
173... with decimal places of -4: string(7) "-20,000"
174... with decimal places of -5: string(1) "0"
175... with decimal places of %i: string(1) "0"
176testing int(999)
177... with decimal places of 0: string(3) "999"
178... with decimal places of 1: string(5) "999.0"
179... with decimal places of 2: string(6) "999.00"
180... with decimal places of 3: string(7) "999.000"
181... with decimal places of 4: string(8) "999.0000"
182... with decimal places of 5: string(9) "999.00000"
183... with decimal places of -1: string(5) "1,000"
184... with decimal places of -2: string(5) "1,000"
185... with decimal places of -3: string(5) "1,000"
186... with decimal places of -4: string(1) "0"
187... with decimal places of -5: string(1) "0"
188... with decimal places of %i: string(1) "0"
189testing int(-999)
190... with decimal places of 0: string(4) "-999"
191... with decimal places of 1: string(6) "-999.0"
192... with decimal places of 2: string(7) "-999.00"
193... with decimal places of 3: string(8) "-999.000"
194... with decimal places of 4: string(9) "-999.0000"
195... with decimal places of 5: string(10) "-999.00000"
196... with decimal places of -1: string(6) "-1,000"
197... with decimal places of -2: string(6) "-1,000"
198... with decimal places of -3: string(6) "-1,000"
199... with decimal places of -4: string(1) "0"
200... with decimal places of -5: string(1) "0"
201... with decimal places of %i: string(1) "0"
202testing float(999)
203... with decimal places of 0: string(3) "999"
204... with decimal places of 1: string(5) "999.0"
205... with decimal places of 2: string(6) "999.00"
206... with decimal places of 3: string(7) "999.000"
207... with decimal places of 4: string(8) "999.0000"
208... with decimal places of 5: string(9) "999.00000"
209... with decimal places of -1: string(5) "1,000"
210... with decimal places of -2: string(5) "1,000"
211... with decimal places of -3: string(5) "1,000"
212... with decimal places of -4: string(1) "0"
213... with decimal places of -5: string(1) "0"
214... with decimal places of %i: string(1) "0"
215testing float(-999)
216... with decimal places of 0: string(4) "-999"
217... with decimal places of 1: string(6) "-999.0"
218... with decimal places of 2: string(7) "-999.00"
219... with decimal places of 3: string(8) "-999.000"
220... with decimal places of 4: string(9) "-999.0000"
221... with decimal places of 5: string(10) "-999.00000"
222... with decimal places of -1: string(6) "-1,000"
223... with decimal places of -2: string(6) "-1,000"
224... with decimal places of -3: string(6) "-1,000"
225... with decimal places of -4: string(1) "0"
226... with decimal places of -5: string(1) "0"
227... with decimal places of %i: string(1) "0"
228testing int(999999)
229... with decimal places of 0: string(7) "999,999"
230... with decimal places of 1: string(9) "999,999.0"
231... with decimal places of 2: string(10) "999,999.00"
232... with decimal places of 3: string(11) "999,999.000"
233... with decimal places of 4: string(12) "999,999.0000"
234... with decimal places of 5: string(13) "999,999.00000"
235... with decimal places of -1: string(9) "1,000,000"
236... with decimal places of -2: string(9) "1,000,000"
237... with decimal places of -3: string(9) "1,000,000"
238... with decimal places of -4: string(9) "1,000,000"
239... with decimal places of -5: string(9) "1,000,000"
240... with decimal places of %i: string(1) "0"
241testing int(-999999)
242... with decimal places of 0: string(8) "-999,999"
243... with decimal places of 1: string(10) "-999,999.0"
244... with decimal places of 2: string(11) "-999,999.00"
245... with decimal places of 3: string(12) "-999,999.000"
246... with decimal places of 4: string(13) "-999,999.0000"
247... with decimal places of 5: string(14) "-999,999.00000"
248... with decimal places of -1: string(10) "-1,000,000"
249... with decimal places of -2: string(10) "-1,000,000"
250... with decimal places of -3: string(10) "-1,000,000"
251... with decimal places of -4: string(10) "-1,000,000"
252... with decimal places of -5: string(10) "-1,000,000"
253... with decimal places of %i: string(1) "0"
254testing float(999999)
255... with decimal places of 0: string(7) "999,999"
256... with decimal places of 1: string(9) "999,999.0"
257... with decimal places of 2: string(10) "999,999.00"
258... with decimal places of 3: string(11) "999,999.000"
259... with decimal places of 4: string(12) "999,999.0000"
260... with decimal places of 5: string(13) "999,999.00000"
261... with decimal places of -1: string(9) "1,000,000"
262... with decimal places of -2: string(9) "1,000,000"
263... with decimal places of -3: string(9) "1,000,000"
264... with decimal places of -4: string(9) "1,000,000"
265... with decimal places of -5: string(9) "1,000,000"
266... with decimal places of %i: string(1) "0"
267testing float(-999999)
268... with decimal places of 0: string(8) "-999,999"
269... with decimal places of 1: string(10) "-999,999.0"
270... with decimal places of 2: string(11) "-999,999.00"
271... with decimal places of 3: string(12) "-999,999.000"
272... with decimal places of 4: string(13) "-999,999.0000"
273... with decimal places of 5: string(14) "-999,999.00000"
274... with decimal places of -1: string(10) "-1,000,000"
275... with decimal places of -2: string(10) "-1,000,000"
276... with decimal places of -3: string(10) "-1,000,000"
277... with decimal places of -4: string(10) "-1,000,000"
278... with decimal places of -5: string(10) "-1,000,000"
279... with decimal places of %i: string(1) "0"
280testing int(2147483647)
281... with decimal places of 0: string(13) "2,147,483,647"
282... with decimal places of 1: string(15) "2,147,483,647.0"
283... with decimal places of 2: string(16) "2,147,483,647.00"
284... with decimal places of 3: string(17) "2,147,483,647.000"
285... with decimal places of 4: string(18) "2,147,483,647.0000"
286... with decimal places of 5: string(19) "2,147,483,647.00000"
287... with decimal places of -1: string(13) "2,147,483,650"
288... with decimal places of -2: string(13) "2,147,483,600"
289... with decimal places of -3: string(13) "2,147,484,000"
290... with decimal places of -4: string(13) "2,147,480,000"
291... with decimal places of -5: string(13) "2,147,500,000"
292... with decimal places of %i: string(1) "0"
293testing int(-2147483648)
294... with decimal places of 0: string(14) "-2,147,483,648"
295... with decimal places of 1: string(16) "-2,147,483,648.0"
296... with decimal places of 2: string(17) "-2,147,483,648.00"
297... with decimal places of 3: string(18) "-2,147,483,648.000"
298... with decimal places of 4: string(19) "-2,147,483,648.0000"
299... with decimal places of 5: string(20) "-2,147,483,648.00000"
300... with decimal places of -1: string(14) "-2,147,483,650"
301... with decimal places of -2: string(14) "-2,147,483,600"
302... with decimal places of -3: string(14) "-2,147,484,000"
303... with decimal places of -4: string(14) "-2,147,480,000"
304... with decimal places of -5: string(14) "-2,147,500,000"
305... with decimal places of %i: string(1) "0"
306