1--TEST-- 2Test number_format() - basic function test number_format() 3--FILE-- 4<?php 5/* Prototype : string number_format ( float $number [, int $decimals ] ) 6 * string number_format ( float $number , int $decimals , string $dec_point , string $thousands_sep ) 7 * Description: Format a number with grouped thousands 8 * Source code: ext/standard/string.c 9 */ 10 11echo "*** Testing number_format() : basic functionality ***\n"; 12 13$values = array(1234.5678, 14 -1234.5678, 15 1234.6578e4, 16 -1234.56789e4, 17 0x1234CDEF, 18 02777777777, 19 "123456789", 20 "123.456789", 21 "12.3456789e1", 22 null, 23 true, 24 false); 25 26echo "\n-- number_format tests.....default --\n"; 27for ($i = 0; $i < count($values); $i++) { 28 $res = number_format($values[$i]); 29 var_dump($res); 30} 31 32echo "\n-- number_format tests.....with two dp --\n"; 33for ($i = 0; $i < count($values); $i++) { 34 $res = number_format($values[$i], 2); 35 var_dump($res); 36} 37 38echo "\n-- number_format tests.....English format --\n"; 39for ($i = 0; $i < count($values); $i++) { 40 $res = number_format($values[$i], 2, '.', ' '); 41 var_dump($res); 42} 43 44echo "\n-- number_format tests.....French format --\n"; 45for ($i = 0; $i < count($values); $i++) { 46 $res = number_format($values[$i], 2, ',' , ' '); 47 var_dump($res); 48} 49?> 50===DONE=== 51--EXPECTF-- 52*** Testing number_format() : basic functionality *** 53 54-- number_format tests.....default -- 55string(5) "1,235" 56string(6) "-1,235" 57string(10) "12,346,578" 58string(11) "-12,345,679" 59string(11) "305,450,479" 60string(11) "402,653,183" 61string(11) "123,456,789" 62string(3) "123" 63string(3) "123" 64string(1) "0" 65string(1) "1" 66string(1) "0" 67 68-- number_format tests.....with two dp -- 69string(8) "1,234.57" 70string(9) "-1,234.57" 71string(13) "12,346,578.00" 72string(14) "-12,345,678.90" 73string(14) "305,450,479.00" 74string(14) "402,653,183.00" 75string(14) "123,456,789.00" 76string(6) "123.46" 77string(6) "123.46" 78string(4) "0.00" 79string(4) "1.00" 80string(4) "0.00" 81 82-- number_format tests.....English format -- 83string(8) "1 234.57" 84string(9) "-1 234.57" 85string(13) "12 346 578.00" 86string(14) "-12 345 678.90" 87string(14) "305 450 479.00" 88string(14) "402 653 183.00" 89string(14) "123 456 789.00" 90string(6) "123.46" 91string(6) "123.46" 92string(4) "0.00" 93string(4) "1.00" 94string(4) "0.00" 95 96-- number_format tests.....French format -- 97string(8) "1 234,57" 98string(9) "-1 234,57" 99string(13) "12 346 578,00" 100string(14) "-12 345 678,90" 101string(14) "305 450 479,00" 102string(14) "402 653 183,00" 103string(14) "123 456 789,00" 104string(6) "123,46" 105string(6) "123,46" 106string(4) "0,00" 107string(4) "1,00" 108string(4) "0,00" 109===DONE=== 110