3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //$amount = number_format(9.22337203685E+18,0,'',''); $amount = 223372036849999872; $number_sep = array(); $multi = 1; $exit = false; $i = 1000; for($j=3;$j < 15 ;$j=$j+2) { switch($j) { case 3: $temp = ($amount/$i);$temp = round(($temp - floor($temp)) * 1000,2); echo $temp; if($i < $amount) { if(!$temp) { $number_sep[] = '000'; } else { $amount = $amount - $temp; $number_sep[] = str_pad(round($temp,2),3,'0',STR_PAD_LEFT); } } else { if(!$temp) { $number_sep[] = '000'; } else { $number_sep[] = str_pad(round($temp,2),3,'0',STR_PAD_LEFT); } $exit = true; } break; case $j > 3 : $temp = ($amount/$i);$temp = round(($temp - floor($temp)) * 1000,0); if($i < $amount) { if(!$temp) { $number_sep[] = '00'; } else { $amount = $amount - $temp; echo $temp; $number_sep[] = $temp/($i/100); } } else { if(!$temp) { $number_sep[] = '00'; } else { $number_sep[] = $temp/($i/100); } $exit = true; }; break; } print_r($number_sep); if($exit) { break; } $i = 10 * 10 * $i; } echo implode(',',array_reverse($number_sep));
Output for 5.2.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
875Array ( [0] => 875 ) 990Array ( [0] => 875 [1] => 0.99 ) 1000Array ( [0] => 875 [1] => 0.99 [2] => 0.01 ) 850Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-5 ) 368Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-5 [4] => 3.68E-7 ) 204Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-5 [4] => 3.68E-7 [5] => 2.04E-9 ) 2.04E-9,3.68E-7,8.5E-5,0.01,0.99,875
Output for 5.2.0 - 5.2.1
875Array ( [0] => 875 ) 990Array ( [0] => 875 [1] => 0.99 ) 1000Array ( [0] => 875 [1] => 0.99 [2] => 0.01 ) 850Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-05 ) 368Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-05 [4] => 3.68E-07 ) 204Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-05 [4] => 3.68E-07 [5] => 2.04E-09 ) 2.04E-9,3.68E-7,8.5E-5,0.01,0.99,875
Output for 4.3.0 - 5.1.6
875Array ( [0] => 875 ) 990Array ( [0] => 875 [1] => 0.99 ) 1000Array ( [0] => 875 [1] => 0.99 [2] => 0.01 ) 850Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-05 ) 368Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-05 [4] => 3.68E-07 ) 204Array ( [0] => 875 [1] => 0.99 [2] => 0.01 [3] => 8.5E-05 [4] => 3.68E-07 [5] => 2.04E-09 ) 2.04E-09,3.68E-07,8.5E-05,0.01,0.99,875