Skip to content

Commit 907b554

Browse files
committed
Added new test file and reverted modified test file
1 parent 0478e2e commit 907b554

File tree

2 files changed

+152
-16
lines changed

2 files changed

+152
-16
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
--TEST--
2+
Test number_format() - test function with different decimal places
3+
--FILE--
4+
<?php
5+
$values = array(
6+
1.5151,
7+
15.151,
8+
151.51,
9+
1515.1,
10+
15151,
11+
-1.5151,
12+
-15.151,
13+
-151.51,
14+
-1515.1,
15+
-15151
16+
);
17+
18+
$decimals = array(0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5);
19+
20+
foreach ($values as $value) {
21+
echo 'testing ';
22+
var_dump($value);
23+
24+
foreach ($decimals as $decimal) {
25+
echo '... with decimal places of ' . $decimal . ': ';
26+
var_dump(number_format($value, $decimal));
27+
}
28+
}
29+
30+
?>
31+
--EXPECT--
32+
testing float(1.5151)
33+
... with decimal places of 0: string(1) "2"
34+
... with decimal places of 1: string(3) "1.5"
35+
... with decimal places of 2: string(4) "1.52"
36+
... with decimal places of 3: string(5) "1.515"
37+
... with decimal places of 4: string(6) "1.5151"
38+
... with decimal places of 5: string(7) "1.51510"
39+
... with decimal places of -1: string(1) "0"
40+
... with decimal places of -2: string(1) "0"
41+
... with decimal places of -3: string(1) "0"
42+
... with decimal places of -4: string(1) "0"
43+
... with decimal places of -5: string(1) "0"
44+
testing float(15.151)
45+
... with decimal places of 0: string(2) "15"
46+
... with decimal places of 1: string(4) "15.2"
47+
... with decimal places of 2: string(5) "15.15"
48+
... with decimal places of 3: string(6) "15.151"
49+
... with decimal places of 4: string(7) "15.1510"
50+
... with decimal places of 5: string(8) "15.15100"
51+
... with decimal places of -1: string(2) "20"
52+
... with decimal places of -2: string(1) "0"
53+
... with decimal places of -3: string(1) "0"
54+
... with decimal places of -4: string(1) "0"
55+
... with decimal places of -5: string(1) "0"
56+
testing float(151.51)
57+
... with decimal places of 0: string(3) "152"
58+
... with decimal places of 1: string(5) "151.5"
59+
... with decimal places of 2: string(6) "151.51"
60+
... with decimal places of 3: string(7) "151.510"
61+
... with decimal places of 4: string(8) "151.5100"
62+
... with decimal places of 5: string(9) "151.51000"
63+
... with decimal places of -1: string(3) "150"
64+
... with decimal places of -2: string(3) "200"
65+
... with decimal places of -3: string(1) "0"
66+
... with decimal places of -4: string(1) "0"
67+
... with decimal places of -5: string(1) "0"
68+
testing float(1515.1)
69+
... with decimal places of 0: string(5) "1,515"
70+
... with decimal places of 1: string(7) "1,515.1"
71+
... with decimal places of 2: string(8) "1,515.10"
72+
... with decimal places of 3: string(9) "1,515.100"
73+
... with decimal places of 4: string(10) "1,515.1000"
74+
... with decimal places of 5: string(11) "1,515.10000"
75+
... with decimal places of -1: string(5) "1,520"
76+
... with decimal places of -2: string(5) "1,500"
77+
... with decimal places of -3: string(5) "2,000"
78+
... with decimal places of -4: string(1) "0"
79+
... with decimal places of -5: string(1) "0"
80+
testing int(15151)
81+
... with decimal places of 0: string(6) "15,151"
82+
... with decimal places of 1: string(8) "15,151.0"
83+
... with decimal places of 2: string(9) "15,151.00"
84+
... with decimal places of 3: string(10) "15,151.000"
85+
... with decimal places of 4: string(11) "15,151.0000"
86+
... with decimal places of 5: string(12) "15,151.00000"
87+
... with decimal places of -1: string(6) "15,150"
88+
... with decimal places of -2: string(6) "15,200"
89+
... with decimal places of -3: string(6) "15,000"
90+
... with decimal places of -4: string(6) "20,000"
91+
... with decimal places of -5: string(1) "0"
92+
testing float(-1.5151)
93+
... with decimal places of 0: string(2) "-2"
94+
... with decimal places of 1: string(4) "-1.5"
95+
... with decimal places of 2: string(5) "-1.52"
96+
... with decimal places of 3: string(6) "-1.515"
97+
... with decimal places of 4: string(7) "-1.5151"
98+
... with decimal places of 5: string(8) "-1.51510"
99+
... with decimal places of -1: string(1) "0"
100+
... with decimal places of -2: string(1) "0"
101+
... with decimal places of -3: string(1) "0"
102+
... with decimal places of -4: string(1) "0"
103+
... with decimal places of -5: string(1) "0"
104+
testing float(-15.151)
105+
... with decimal places of 0: string(3) "-15"
106+
... with decimal places of 1: string(5) "-15.2"
107+
... with decimal places of 2: string(6) "-15.15"
108+
... with decimal places of 3: string(7) "-15.151"
109+
... with decimal places of 4: string(8) "-15.1510"
110+
... with decimal places of 5: string(9) "-15.15100"
111+
... with decimal places of -1: string(3) "-20"
112+
... with decimal places of -2: string(1) "0"
113+
... with decimal places of -3: string(1) "0"
114+
... with decimal places of -4: string(1) "0"
115+
... with decimal places of -5: string(1) "0"
116+
testing float(-151.51)
117+
... with decimal places of 0: string(4) "-152"
118+
... with decimal places of 1: string(6) "-151.5"
119+
... with decimal places of 2: string(7) "-151.51"
120+
... with decimal places of 3: string(8) "-151.510"
121+
... with decimal places of 4: string(9) "-151.5100"
122+
... with decimal places of 5: string(10) "-151.51000"
123+
... with decimal places of -1: string(4) "-150"
124+
... with decimal places of -2: string(4) "-200"
125+
... with decimal places of -3: string(1) "0"
126+
... with decimal places of -4: string(1) "0"
127+
... with decimal places of -5: string(1) "0"
128+
testing float(-1515.1)
129+
... with decimal places of 0: string(6) "-1,515"
130+
... with decimal places of 1: string(8) "-1,515.1"
131+
... with decimal places of 2: string(9) "-1,515.10"
132+
... with decimal places of 3: string(10) "-1,515.100"
133+
... with decimal places of 4: string(11) "-1,515.1000"
134+
... with decimal places of 5: string(12) "-1,515.10000"
135+
... with decimal places of -1: string(6) "-1,520"
136+
... with decimal places of -2: string(6) "-1,500"
137+
... with decimal places of -3: string(6) "-2,000"
138+
... with decimal places of -4: string(1) "0"
139+
... with decimal places of -5: string(1) "0"
140+
testing int(-15151)
141+
... with decimal places of 0: string(7) "-15,151"
142+
... with decimal places of 1: string(9) "-15,151.0"
143+
... with decimal places of 2: string(10) "-15,151.00"
144+
... with decimal places of 3: string(11) "-15,151.000"
145+
... with decimal places of 4: string(12) "-15,151.0000"
146+
... with decimal places of 5: string(13) "-15,151.00000"
147+
... with decimal places of -1: string(7) "-15,150"
148+
... with decimal places of -2: string(7) "-15,200"
149+
... with decimal places of -3: string(7) "-15,000"
150+
... with decimal places of -4: string(7) "-20,000"
151+
... with decimal places of -5: string(1) "0"

ext/standard/tests/math/number_format_negative_zero.phpt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,13 @@ Prevent number_format from returning negative zero
44
<?php
55

66
$number = -1.15E-15;
7-
var_dump($number);
8-
var_dump(number_format($number, 2));
97

10-
$number = -0.01;
118
var_dump($number);
129
var_dump(number_format($number, 2));
13-
14-
$number = -1234567.89;
15-
var_dump($number);
16-
var_dump(number_format($number, -3));
17-
18-
$number = -1234321.09;
19-
var_dump($number);
20-
var_dump(number_format($number, -3));
10+
var_dump(number_format(-0.01, 2));
2111

2212
?>
2313
--EXPECT--
2414
float(-1.15E-15)
2515
string(4) "0.00"
26-
float(-0.01)
2716
string(5) "-0.01"
28-
float(-1234567.89)
29-
string(10) "-1,235,000"
30-
float(-1234321.09)
31-
string(10) "-1,234,000"

0 commit comments

Comments
 (0)