round_basic.phpt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. --TEST--
  2. Test round() - basic function test for round()
  3. --INI--
  4. precision=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. echo "*** Testing round() : basic functionality ***\n";
  13. $values = array(123456789,
  14. 123.456789,
  15. -4.5679123,
  16. 1.23E4,
  17. -4.567E3,
  18. 0x234567,
  19. 067777777,
  20. "1.234567",
  21. "2.3456789e8",
  22. "0x1234CDEF");
  23. $precision = array(2,
  24. 8,
  25. 0x3,
  26. 04,
  27. 3.6,
  28. "2",
  29. "0x03",
  30. "04",
  31. "3.6",
  32. "2.1e1",
  33. null,
  34. true,
  35. false);
  36. for ($i = 0; $i < count($values); $i++) {
  37. echo "round: $values[$i]\n";
  38. for ($j = 0; $j < count($precision); $j++) {
  39. $res = round($values[$i], $precision[$j]);
  40. echo "...with precision $precision[$j]-> ";
  41. var_dump($res);
  42. }
  43. }
  44. ?>
  45. ===Done===
  46. --EXPECTF--
  47. *** Testing round() : basic functionality ***
  48. round: 123456789
  49. ...with precision 2-> float(123456789)
  50. ...with precision 8-> float(123456789)
  51. ...with precision 3-> float(123456789)
  52. ...with precision 4-> float(123456789)
  53. ...with precision 3.6-> float(123456789)
  54. ...with precision 2-> float(123456789)
  55. ...with precision 0x03-> float(123456789)
  56. ...with precision 04-> float(123456789)
  57. ...with precision 3.6-> float(123456789)
  58. ...with precision 2.1e1-> float(123456789)
  59. ...with precision -> float(123456789)
  60. ...with precision 1-> float(123456789)
  61. ...with precision -> float(123456789)
  62. round: 123.456789
  63. ...with precision 2-> float(123.46)
  64. ...with precision 8-> float(123.456789)
  65. ...with precision 3-> float(123.457)
  66. ...with precision 4-> float(123.4568)
  67. ...with precision 3.6-> float(123.457)
  68. ...with precision 2-> float(123.46)
  69. ...with precision 0x03-> float(123.457)
  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)
  76. round: -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 0x03-> float(-4.568)
  84. ...with precision 04-> float(-4.5679)
  85. ...with precision 3.6-> float(-4.568)
  86. ...with precision 2.1e1-> float(-4.5679123)
  87. ...with precision -> float(-5)
  88. ...with precision 1-> float(-4.6)
  89. ...with precision -> float(-5)
  90. round: 12300
  91. ...with precision 2-> float(12300)
  92. ...with precision 8-> float(12300)
  93. ...with precision 3-> float(12300)
  94. ...with precision 4-> float(12300)
  95. ...with precision 3.6-> float(12300)
  96. ...with precision 2-> float(12300)
  97. ...with precision 0x03-> float(12300)
  98. ...with precision 04-> float(12300)
  99. ...with precision 3.6-> float(12300)
  100. ...with precision 2.1e1-> float(12300)
  101. ...with precision -> float(12300)
  102. ...with precision 1-> float(12300)
  103. ...with precision -> float(12300)
  104. round: -4567
  105. ...with precision 2-> float(-4567)
  106. ...with precision 8-> float(-4567)
  107. ...with precision 3-> float(-4567)
  108. ...with precision 4-> float(-4567)
  109. ...with precision 3.6-> float(-4567)
  110. ...with precision 2-> float(-4567)
  111. ...with precision 0x03-> float(-4567)
  112. ...with precision 04-> float(-4567)
  113. ...with precision 3.6-> float(-4567)
  114. ...with precision 2.1e1-> float(-4567)
  115. ...with precision -> float(-4567)
  116. ...with precision 1-> float(-4567)
  117. ...with precision -> float(-4567)
  118. round: 2311527
  119. ...with precision 2-> float(2311527)
  120. ...with precision 8-> float(2311527)
  121. ...with precision 3-> float(2311527)
  122. ...with precision 4-> float(2311527)
  123. ...with precision 3.6-> float(2311527)
  124. ...with precision 2-> float(2311527)
  125. ...with precision 0x03-> float(2311527)
  126. ...with precision 04-> float(2311527)
  127. ...with precision 3.6-> float(2311527)
  128. ...with precision 2.1e1-> float(2311527)
  129. ...with precision -> float(2311527)
  130. ...with precision 1-> float(2311527)
  131. ...with precision -> float(2311527)
  132. round: 14680063
  133. ...with precision 2-> float(14680063)
  134. ...with precision 8-> float(14680063)
  135. ...with precision 3-> float(14680063)
  136. ...with precision 4-> float(14680063)
  137. ...with precision 3.6-> float(14680063)
  138. ...with precision 2-> float(14680063)
  139. ...with precision 0x03-> float(14680063)
  140. ...with precision 04-> float(14680063)
  141. ...with precision 3.6-> float(14680063)
  142. ...with precision 2.1e1-> float(14680063)
  143. ...with precision -> float(14680063)
  144. ...with precision 1-> float(14680063)
  145. ...with precision -> float(14680063)
  146. round: 1.234567
  147. ...with precision 2-> float(1.23)
  148. ...with precision 8-> float(1.234567)
  149. ...with precision 3-> float(1.235)
  150. ...with precision 4-> float(1.2346)
  151. ...with precision 3.6-> float(1.235)
  152. ...with precision 2-> float(1.23)
  153. ...with precision 0x03-> float(1.235)
  154. ...with precision 04-> float(1.2346)
  155. ...with precision 3.6-> float(1.235)
  156. ...with precision 2.1e1-> float(1.234567)
  157. ...with precision -> float(1)
  158. ...with precision 1-> float(1.2)
  159. ...with precision -> float(1)
  160. round: 2.3456789e8
  161. ...with precision 2-> float(234567890)
  162. ...with precision 8-> float(234567890)
  163. ...with precision 3-> float(234567890)
  164. ...with precision 4-> float(234567890)
  165. ...with precision 3.6-> float(234567890)
  166. ...with precision 2-> float(234567890)
  167. ...with precision 0x03-> float(234567890)
  168. ...with precision 04-> float(234567890)
  169. ...with precision 3.6-> float(234567890)
  170. ...with precision 2.1e1-> float(234567890)
  171. ...with precision -> float(234567890)
  172. ...with precision 1-> float(234567890)
  173. ...with precision -> float(234567890)
  174. round: 0x1234CDEF
  175. ...with precision 2-> float(305450479)
  176. ...with precision 8-> float(305450479)
  177. ...with precision 3-> float(305450479)
  178. ...with precision 4-> float(305450479)
  179. ...with precision 3.6-> float(305450479)
  180. ...with precision 2-> float(305450479)
  181. ...with precision 0x03-> float(305450479)
  182. ...with precision 04-> float(305450479)
  183. ...with precision 3.6-> float(305450479)
  184. ...with precision 2.1e1-> float(305450479)
  185. ...with precision -> float(305450479)
  186. ...with precision 1-> float(305450479)
  187. ...with precision -> float(305450479)
  188. ===Done===