1--TEST--
2Test round() - basic function test for round()
3--INI--
4precision=14
5--FILE--
6<?php
7/* Prototype  : float round  ( float $val  [, int $precision  ] )
8 * Description: Returns the rounded value of val  to specified precision (number of digits
9 * after the decimal point)
10 * Source code: ext/standard/math.c
11 */
12
13echo "*** Testing round() : basic functionality ***\n";
14
15$values = array(123456789,
16				123.456789,
17				-4.5679123,
18				1.23E4,
19				-4.567E3,
20				0x234567,
21				067777777,
22				"1.234567",
23				"2.3456789e8");
24
25$precision = array(2,
26				8,
27				0x3,
28				04,
29				3.6,
30				"2",
31				"04",
32				"3.6",
33				"2.1e1",
34				null,
35				true,
36				false);
37
38for ($i = 0; $i < count($values); $i++) {
39	echo "round: $values[$i]\n";
40	for ($j = 0; $j < count($precision); $j++) {
41		$res = round($values[$i], $precision[$j]);
42		echo "...with precision $precision[$j]-> ";
43		var_dump($res);
44	}
45}
46?>
47===Done===
48--EXPECTF--
49*** Testing round() : basic functionality ***
50round: 123456789
51...with precision 2-> float(123456789)
52...with precision 8-> float(123456789)
53...with precision 3-> float(123456789)
54...with precision 4-> float(123456789)
55...with precision 3.6-> float(123456789)
56...with precision 2-> float(123456789)
57...with precision 04-> float(123456789)
58...with precision 3.6-> float(123456789)
59...with precision 2.1e1-> float(123456789)
60...with precision -> float(123456789)
61...with precision 1-> float(123456789)
62...with precision -> float(123456789)
63round: 123.456789
64...with precision 2-> float(123.46)
65...with precision 8-> float(123.456789)
66...with precision 3-> float(123.457)
67...with precision 4-> float(123.4568)
68...with precision 3.6-> float(123.457)
69...with precision 2-> float(123.46)
70...with precision 04-> float(123.4568)
71...with precision 3.6-> float(123.457)
72...with precision 2.1e1-> float(123.456789)
73...with precision -> float(123)
74...with precision 1-> float(123.5)
75...with precision -> float(123)
76round: -4.5679123
77...with precision 2-> float(-4.57)
78...with precision 8-> float(-4.5679123)
79...with precision 3-> float(-4.568)
80...with precision 4-> float(-4.5679)
81...with precision 3.6-> float(-4.568)
82...with precision 2-> float(-4.57)
83...with precision 04-> float(-4.5679)
84...with precision 3.6-> float(-4.568)
85...with precision 2.1e1-> float(-4.5679123)
86...with precision -> float(-5)
87...with precision 1-> float(-4.6)
88...with precision -> float(-5)
89round: 12300
90...with precision 2-> float(12300)
91...with precision 8-> float(12300)
92...with precision 3-> float(12300)
93...with precision 4-> float(12300)
94...with precision 3.6-> float(12300)
95...with precision 2-> float(12300)
96...with precision 04-> float(12300)
97...with precision 3.6-> float(12300)
98...with precision 2.1e1-> float(12300)
99...with precision -> float(12300)
100...with precision 1-> float(12300)
101...with precision -> float(12300)
102round: -4567
103...with precision 2-> float(-4567)
104...with precision 8-> float(-4567)
105...with precision 3-> float(-4567)
106...with precision 4-> float(-4567)
107...with precision 3.6-> float(-4567)
108...with precision 2-> float(-4567)
109...with precision 04-> float(-4567)
110...with precision 3.6-> float(-4567)
111...with precision 2.1e1-> float(-4567)
112...with precision -> float(-4567)
113...with precision 1-> float(-4567)
114...with precision -> float(-4567)
115round: 2311527
116...with precision 2-> float(2311527)
117...with precision 8-> float(2311527)
118...with precision 3-> float(2311527)
119...with precision 4-> float(2311527)
120...with precision 3.6-> float(2311527)
121...with precision 2-> float(2311527)
122...with precision 04-> float(2311527)
123...with precision 3.6-> float(2311527)
124...with precision 2.1e1-> float(2311527)
125...with precision -> float(2311527)
126...with precision 1-> float(2311527)
127...with precision -> float(2311527)
128round: 14680063
129...with precision 2-> float(14680063)
130...with precision 8-> float(14680063)
131...with precision 3-> float(14680063)
132...with precision 4-> float(14680063)
133...with precision 3.6-> float(14680063)
134...with precision 2-> float(14680063)
135...with precision 04-> float(14680063)
136...with precision 3.6-> float(14680063)
137...with precision 2.1e1-> float(14680063)
138...with precision -> float(14680063)
139...with precision 1-> float(14680063)
140...with precision -> float(14680063)
141round: 1.234567
142...with precision 2-> float(1.23)
143...with precision 8-> float(1.234567)
144...with precision 3-> float(1.235)
145...with precision 4-> float(1.2346)
146...with precision 3.6-> float(1.235)
147...with precision 2-> float(1.23)
148...with precision 04-> float(1.2346)
149...with precision 3.6-> float(1.235)
150...with precision 2.1e1-> float(1.234567)
151...with precision -> float(1)
152...with precision 1-> float(1.2)
153...with precision -> float(1)
154round: 2.3456789e8
155...with precision 2-> float(234567890)
156...with precision 8-> float(234567890)
157...with precision 3-> float(234567890)
158...with precision 4-> float(234567890)
159...with precision 3.6-> float(234567890)
160...with precision 2-> float(234567890)
161...with precision 04-> float(234567890)
162...with precision 3.6-> float(234567890)
163...with precision 2.1e1-> float(234567890)
164...with precision -> float(234567890)
165...with precision 1-> float(234567890)
166...with precision -> float(234567890)
167===Done===
168